Menu

#193 register_hotkey: how to get keycodes

Unscheduled
closed
nobody
None
Feature
5
2021-10-18
2021-01-02
No

I'm trying to have end users pick hotkeys but I am encountering 2 issues:

a) how could I make a UI where the user hits a key sequence and I translate it to the vkey code reliable (I can make it work for a basic ctrl-shift-h for instance as h is a standard key and these have same name in tk and in twapi but what about more obscure keys like OEM3...)

b) some hotkeys appear to work but don't - for instance
% twapi::register_hotkey shift debug
49375
even though just shift is probably to broad and fails somewhere but silently?

Discussion

  • Anonymous

    Anonymous - 2021-01-04

    a) See https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes for key codes. Either use the mnemonic without the VK_ or use the numeric key code.

    b) To bind shift,

    twapi::register_hotkey shift-shift debug
    

    "shift" by itself means shift key with no modifiers. Since the shift modifier is present always present when shift key is pressed, that will never trigger. It is however not a good idea to bind shift/ctrl etc by themselves.

     
  • Laurent Demailly

    Thanks, yes I am aware of that page, that's not what I am asking though, I am asking how can I write an app where the user clicks my tk button and then hits the hotkey sequence of their choosing and I capture/translate that to a format that would work for register_hotkey (outside of the simple combos)

    For b) the issue isn't what as much what is the syntax (though that's useful to know, thanks) but why is something that doesn't work not generating an error (and yes I realize " shift is probably to broad " ie not a good idea, it was just an example of "success" of the api yet non functional hotkey)

     
  • Anonymous

    Anonymous - 2021-01-04

    Re. b), the API does succeed (this is Windows succeeding, not twapi which just passes through to Windows) because if someone sends key messages with modifier set to shift and a key code of 0, it will trigger the hotkey. However, I do not know how one can do that from the keyboard as opposed to programmatically.

    Re. a), well you are asking about translating Tk keysyms to keycodes then. Luckily there is a sample widget - see https://sourceforge.net/p/windowstoolset/code/ci/default/tree/apps/wits/widgets.tcl#l2772 and https://sourceforge.net/p/windowstoolset/code/ci/default/tree/apps/wits/widgets.tcl#l2835

    If you download the WiTS application and try the hotkey editor, you will see how it works.

     
  • Ashok P. Nadkarni

    • status: open --> closed
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB