Page 1 of 1

Extra constants for AddKeyboardShortcut

Posted: Tue Feb 26, 2013 11:02 pm
by Techie42
Hi all,

I'd like extra constants for the other keys on some keyboards, such as the following:
  • "=" (equals sign)
    "+" (plus sign when equals sign is shifted)
    "#"
    "["
    "]"
    etc...
I know I can use the Windows API, but this is not cross-platform.

One reason for requesting extra constants is that not all keyboards have a numeric keypad (or the numeric keypad is overlaid on to other keys on some laptops), and even though #PB_Shortcut_Add exists, I also need to be able to refer to the "+" sign when the "=" key is shifted (I'm using a UK keyboard).

I hope the above makes sense.

Re: Extra constants for AddKeyboardShortcut

Posted: Tue Feb 26, 2013 11:12 pm
by davido
Hi Techie42,

Check Demivec's code in this link:

http://www.purebasic.fr/english/viewtop ... =3&t=52683

Re: Extra constants for AddKeyboardShortcut

Posted: Wed Feb 27, 2013 12:10 am
by Techie42
Hi davido,

Thanks for the quick reply :D

I believe if I use the ShortcutGadget, then I will need to get the end-user to configure the shortcuts themselves whenever they install my software, as it looks like I would need to use this to capture whatever the relevant shortcut is on their computer.

I believe the Windows API defines two keyboard constants: VK_ADD and VK_OEM_PLUS. My understanding is that VK_ADD is the "+" key on the numeric keypad, and VK_OEM_PLUS is the "+" key with the "=" sign.

Microsoft state in their documentation that VK_OEM_PLUS is valid for any country / region, so it seems that the "+" sign on the "=" key is available on all keyboards, and available as VK_OEM_PLUS.

If this is the case, then it would be nice for this same shortcut to be available from within PureBasic, and be cross-platform.

When I use the example in the PureBasic documentation on ShortcutGadget, and output the gadget state to the debug window, the value 65723 is returned for the "+" key on the "=" key (which is Shift + "=" on my UK keyboard). If I then use this value in AddKeyboardShortcut (instead of #PB_Shortcut_Add), then the shortcut works as I expect. However, I cannot assume that this numerical value would be valid for all keyboards.

I have tried using the constant #VK_OEM_PLUS which is already defined within PureBasic, but this has the value 187, so it appears it is not for use with AddKeyboardShortcut.

I hope you can see my dilemma :(

Re: Extra constants for AddKeyboardShortcut

Posted: Wed Feb 27, 2013 10:54 pm
by Techie42
I've discovered something!

If I use #VK_OEM_PLUS and #VK_OEM_MINUS, then I can get AddKeyboardShortcut to work, sort of as I wish.

The minus key (-) satisfies #VK_OEM_MINUS, and the equals key (=) satisfies #VK_OEM_PLUS. My UK keyboard has a minus key and underscore key (SHIFT + -), and an equals key and a plus key (SHIFT + =).

I'm not sure if this is the expected response / interaction, but it will do for me. This appears to work on my MS Windows desktop PCs and MS Windows laptops, so it is consistent (for now).

Please feel free to shed any further light on this matter :|