use PostMessage to stuff keys into NP

  • David McDivitt
    David McDivitt

    I'm trying to do some automation. I want NP to do a find shortly after opening. If I find the window with class Notepad++ and stuff keystrokes with PostMessage, it doesn't do anything. That's the parent window and has the menu bar. If I find the child window with class Scintilla and stuff keystrokes there, the CTRL-F is ignored, I can't tell, and the search text is inserted at the top of the document as if I typed it. What I need to do is stuff a CTRL-F into the parent window, cause the search dialog to open, find that window, then stuff the search text. I can't get anything to happen with the parent window. Can anyone help with this? Thanks

  • cchris

    You'd need to:
    * send WM_COMMAND with the proper ID to the Npp window
    * Wait for dialog to open
    * locate children of the dialog box and add contents there, including clicking the button.

    Won't a native Notepad++ macro work in a simpler way?


  • Do you really need to automate through keystrokes and messages?  To automate Notepad++ to search on startup, I would rather use PythonScript plugin, and generate a script before starting Notepad++, that will be executed on startup.  So that you do not have to modify the script dynamically, you can use an "import" of the script to execute, in a "try: import … except ImportError:".