Skip to main content
dublove
Legend
Oct 28, 2026 2:46 AM UTC
Question

Is it possible to know which keys are currently being pressed to trigger the current script?

Hello everyone.

I want to set two options for a script.
If I just pressed Ctrl+3, execute a support.
If I just pressed Ctrl+4, execute b support.
Is it possible to detect which two keys were pressed to start the script?

    5 replies

    m1b
    Community Expert
    Community Expert
    Oct 28, 2026 9:41 AM UTC

    Hi ​@dublove no I don’t think it will work the way you want because we don’t have good access to the keyboard via the scripting API, and none for the keyboard history, eg. what keys did you use to launch the script.

    You seem to like the idea of “run one script but depending on something, get two different scripts”. This is really almost always unnecessary.

    The normal way to do it is (a) put all your shared logic in a “//@include” file and (b) create TWO scripts which are the “entry points” to your main logic. Then you can assign shortcuts to those two scripts and you achieve your aim. If that doesn’t work in your case, would you mind explaining exactly why not?

    Translate
    dublove
    dubloveAuthor
    Legend
    Oct 28, 2026 10:16 AM UTC

    Hi m1b.

    That's how I used to do it.
    But I always wonder if there's anything more convenient.

    Translate
    Community Expert
    Oct 28, 2026 3:32 AM UTC

    You can try the property given below. However, I don’t think that would be able to detect what shortcut was used to trigger the script. Easiest option is to use two jsx with different shortcuts assigned to them.

    ScriptUI.environment.keyboardState
    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Oct 28, 2026 10:19 AM UTC

    Hi Manan Joshi.

    I just want to use two shortcuts to drive the same script.

    Then determine which one I pressed and choose to execute a different plan, so my jsx file still only has one, but I did two things.

    Translate
    Community Expert
    Oct 28, 2026 10:30 AM UTC

    I understand what you are trying to do. I think this is not possible, but you can try using the property I gave above. Or probably introduce a UI to allow the user to select which option to execute

    Translate
    -Manan