Trigger a Notepad plugin based on CURSOR & CNTL-KEY inputs

  • bob kennelly

    bob kennelly - 2014-01-30

    Hello using Notepad, would it be possible to create a Notepad plugin that would allow me to place a cursor on a word in a Notepad text file and when i select a CNTL-KEY, Notepad would trigger a call to a plugin which would capture the word(cursor) and then do a lookup of that word(cursor) on a key|value list? ie

    key |value

    And before using this plugin, i would have already created the key|value list in advance, so the plugin would use the word(cursor) to do a lookup on the key|value list and when a word(key) is found, the plugin would open the text filename(value) associated with that word(key) in Notepad?

    For example, if i place the cursor on the word "function", select a CNTL-KEY, then Notepad would open the first filename(value) “c:\file1” associated with the word(cursor)?

    Thanks for any suggestions or recommendations!

  • Andreas Jonsson

    Andreas Jonsson - 2014-01-30

    This is easily done using the Python plugin.

    First install "Python script" if it's not already installed. (Plugins -> Plugin manager, select "Python script", click Install).

    Then add the following script. Go to Plugins -> Python script -> New script, then type in a name, then copy and paste the following:

    curPos = editor.getCurrentPos()
    wordStart = editor.wordStartPosition(curPos, True)
    wordEnd = editor.wordEndPosition(curPos, True)
    word = editor.getTextRange(wordStart, wordEnd)
    keyValues = { 'test1': 'c:\\users\\andreas\\desktop\\test1.txt', 'test2': 'c:\\users\\andreas\\desktop\\test2.txt'}
    if word in keyValues:

    Now you can run the script by selecting Plugins -> Python script -> Scripts -> {name}. If you want to map a shortcut key, follow these instructions:

    You define the key-value list on line 5 following ordinary Python dictionary syntax.

  • bob kennelly

    bob kennelly - 2014-01-30

    Great thanks very much Andreas, great reason to learn Python too! have a great one!


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks