• Login
Community
  • Login

How to capture what user is typing

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
12 Posts 2 Posters 7.3k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    dail
    last edited by dail Sep 2, 2016, 12:36 PM Sep 2, 2016, 12:35 PM

    Since you are wanting to receive notifications that something has happened you’d want to use the beNotified() function instead of messageProc().

    That being said you won’t receive WM_KEYDOWN notifications. Those are handled by Notepad++/Scintilla. What you normally do is catch notifications from Scintilla that tells you the user has added (or removed) text by catching the SCN_MODIFIED notification which has the info you need (e.g. position, text). You can also catch SCN_MODIFYATTEMPTRO which tells you a read-only document was attempted to be modified…but I don’t believe this notification tells you what was actually attempted.

    If indeed you are actually needing the raw WM_KEYDOWN notifications there are ways of subclassing (superclassing?) the Notepad++ window and catching them before Notepad++ does…but that is beyond by Win32 API knowledge, but I do know some plugins do that.

    1 Reply Last reply Reply Quote 0
    • B
      bycn82 bbbb
      last edited by Sep 3, 2016, 11:41 AM

      Thanks,

      I already got notified. but the notifyCode->ch is always equals to 0

      Can you please help to explain how can I check what user is typed?

      1 Reply Last reply Reply Quote 0
      • D
        dail
        last edited by dail Sep 3, 2016, 3:17 PM Sep 3, 2016, 3:16 PM

        You should read the documentation on those notifications. SCN_MODIFIED does not use the ch field, it uses the text field because the user could paste multiple characters (or delete a range of text).

        If indeed you do want individual characters only (and skip any paste/deletes) then you can catch SCN_CHARADDED notifications which does use ch.

        1 Reply Last reply Reply Quote 0
        • B
          bycn82 bbbb
          last edited by Sep 6, 2016, 12:52 AM

          I want to be notified when user typed “backspace”, but maybe VK_BACK is the not correct value. or maybe it was not captured in SCN_MODIFIED/CHARADDED. any recommendation?

          1 Reply Last reply Reply Quote 0
          • D
            dail
            last edited by Sep 6, 2016, 1:54 AM

            SCN_MODIFIED does tell you when a character (or range of characters) is deleted, but not necessarily due to the backspace key. The modificationType will have the SC_MOD_DELETETEXT flag set.

            If you are needing to capture actual keyboard input and not just changes to the text document then you’ll have to go the subclassing/superclassing route.

            1 Reply Last reply Reply Quote 0
            • B
              bycn82 bbbb
              last edited by Sep 6, 2016, 4:11 AM

              Yes,
              the BACKSPACE will trigger the notification with SC_MOD_DELETETEXT bit in the modificationType. Thanks.

              I got another question.
              Currently I bind the hotkey with the function using the menu. But is it possible to hide the menu or is there any another to link the hotkey and func?

              1 Reply Last reply Reply Quote 0
              • D
                dail
                last edited by dail Sep 6, 2016, 1:59 PM Sep 6, 2016, 12:11 PM

                No it is only possible using the FuncItem struct which requires a hotkey.

                Edit: Actually it doesn’t require a hotkey, however the struct is the only way to register functions with Notepad++…which automatically show up in the menu.

                1 Reply Last reply Reply Quote 0
                • B
                  bycn82 bbbb
                  last edited by Sep 6, 2016, 3:15 PM

                  How to response the VK_ESCAPE? currently I am binding the ESC on the menu command, it works. but I was wondering whether I can filter the VK_ESCAPE somewhere or I can dynamically bind it as a hotkey for a function.

                  1 Reply Last reply Reply Quote 0
                  • D
                    dail
                    last edited by Sep 6, 2016, 3:19 PM

                    As far as I know you can’t dynamically bind shortcuts.

                    1 Reply Last reply Reply Quote 0
                    • B
                      bycn82 bbbb
                      last edited by Sep 7, 2016, 2:44 PM

                      Hi Dali,
                      I was trying to intercept the user typing by receiving the notification when editor is read-only, so far, it works good. but read-only editor is not an ultimate solution, I wondering is there any way to ignore the key press on the editor and interact with the key pressing?
                      Regards,

                      1 Reply Last reply Reply Quote 0
                      • D
                        dail
                        last edited by Sep 7, 2016, 3:09 PM

                        I’m not sure. I’m not saying it is impossible though, just don’t know how.

                        1 Reply Last reply Reply Quote 0
                        11 out of 12
                        • First post
                          11/12
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors