Skip to content

Script bound to Ctrl-only keycombo can't be opened for edit by holding Ctrl and clicking it in menu #319

Open

Description

@alankilborn

Create simple script and give it a simple name (e.g. t.py):

from Npp import *
notepad.prompt('hello:', 'there', 'dude')

Run the script from the menu to see it works:
image

Close the t.py file.

Navigate to the script in the menu again, but this time hold Ctrl down while clicking t here:

image

Observe that t.py opens (correctly) into a Notepad++ tab. Close this N++ tab.

Assign a shortcut that only involves the Ctrl key (e.g. Ctrl + e) to the running of this script, and it will appear like this in the menu:
image

With that menu showing, point to the t script, hold Ctrl down, and click.

Expected result: t.py opens into a new Notepad++ tab.
Actual result: the script runs.

Using Notepad++ 8.6 64-bit with PS 3.0.16.0.

Activity

  1. chcg commented on Dec 23, 2023

    @chcg
    Collaborator

    See

    /* If the shortcut for the given script number does not have a control in it,
    * (or no shortcut key is assigned), then we can pretend the user clicked the menu option.
    * runScript() will then check if Ctrl is held down, if it is, it will edit the script.
    * Obviously if this menu item's key DOES have Ctrl in it, (and we're on N++ 5.8 or upwards)
    * then we can't tell the difference (as we haven't subclassed N++).
    * If that's the case, then ctrl-click won't work. That's just tough, I think.

    From plugin perspective Ctrl+Shortcutkey, Mouseclick menuitem with script and Mouseclick menuitem with script+Ctrl all are connected just the call of the script function from N++ and is not easily possible to find out where it is coming from.

    As Workaround a shortcut with Ctrl+Shift or Ctrl+Alt could be used instead.

  2. alankilborn commented on Dec 23, 2023

    @alankilborn
    Author

    OK, makes sense.
    Thanks for investigating.


    As Workaround a shortcut with Ctrl+Shift or Ctrl+Alt could be used instead.

    Well, users want keycombos as they want them.
    Nobody would want to add an extra modifier in just for this capability.

  3. vinsworldcom commented on Jan 5, 2024

    @vinsworldcom
    Contributor

    Interesting. I never realized this could be considered a bug as if you use the "Scripts" submenu, t should be there also and you should be able to CTRL+Right Mouse or CTRL+Enter to open in Notepad++. That's what I always have done assuming that the CTRL+<somthing> shortcut in PythonScript only worked on the "Scripts" submenu.

    Cheers.

  4. alankilborn commented on Jan 5, 2024

    @alankilborn
    Author

    if you use the "Scripts" submenu, t should be there also

    Yes, this works. The problem comes in when you have hundreds(?!) of scripts in many subfolders, and finding just one can be a lengthy scrolling/digging-down process, and especially annoying if you can plainly see the script you want to edit in the "first-level" PS menu.

    [ I probably need a script that prompts me for a partial name, and then finds and opens (for edit) it for me. :-) ]

    should be able to CTRL+Right Mouse or CTRL+Enter to open

    CTRL+Enter works, but I'm unsure about how CTRL+Right Mouse does anything?

  5. vinsworldcom commented on Jan 5, 2024

    @vinsworldcom
    Contributor

    CTRL+Right Mouse does anything?

    I obviously meant using the mouse with your RIGHT HAND to click the LEFT mouse button ... he says after holding both hands in front of his face with the thumbs out to see which one spells the letter L.

    Cheers.

  6. alankilborn commented on Jan 5, 2024

    @alankilborn
    Author

    Super-confused now. :-)
    Think I will just ignore prior references to CTRL+Right Mouse...

  7. alankilborn commented on Jan 6, 2024

    @alankilborn
    Author

    Somewhat maddeningly:

    • put a script (with no bound keycombo, for the sake of simplicity) on Notepad++'s editor right-click menu (i.e. contextMenu.xml)
    • have some logic in the script so that it acts differently when Ctrl key is down vs not-down (see sample code below)
    • try to run the script with the alternate logic asserted (i.e., hold Ctrl while choosing the script entry in N++ editor right-click menu)
    • be befuddled when the script opens in a new tab rather than executing
    • (change your script to use Shift, not Ctrl)

    sample code:

    from ctypes import (WinDLL)
    
    def ctrl_held(self):
        VK_CONTROL = 0x11
        user32 = WinDLL('user32')
        return (user32.GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0
    

    usage of defined function:

    ...
    if self.ctrl_held():
        ...logic path 1...
    else:
        ...logic path 2...
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions