Page 1 of 1

Help Needed for ShortCutGadget()

Posted: Sat Aug 15, 2009 8:41 am
by akj
I see what the ShortCutGadget() does, but how is it useful?

Would it normally be used as an invisible gadget?

Can someone please provide a working example of using this gadget.

Posted: Sat Aug 15, 2009 9:58 am
by Progi1984

Posted: Sat Aug 15, 2009 10:19 am
by akj
@Progi1984:

Thanks for your help, but I had already spotted that post, however I still don't see how the ShortcutGadget is intended to be used in practice.

In what sort of applications would this be a valuable gadget to have?

Is it's only use to convert a keypress to an Ascii representation or has it got other useful properties?

Posted: Sat Aug 15, 2009 2:03 pm
by freak
> I still don't see how the ShortcutGadget is intended to be used in practice.

It is intended to let the user choose a keyboard shortcut for something. Just like the IDE in its Preferences does. Get/SetGadgetState() can be used on the gadget to get/set the current shortcut. The values are passed using the #PB_Shortcut_XXX constants, so you could directly use the GetGadgetState() value from the ShortcutGadget() in a call to AddKeyboardShortcut() to add this shortcut to your window.

Posted: Sat Aug 15, 2009 5:55 pm
by netmaestro
You can also use it as a hotkey gadget for your window:

Code: Select all

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)

ShortcutGadget(0,10,10,100,20, #PB_Shortcut_Alt|#PB_Shortcut_A)

sc.w = SendMessage_(GadgetID(0),#HKM_GETHOTKEY,0,0)
SendMessage_(WindowID(0), #WM_SETHOTKEY, sc, 0)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Minimize the window and hit the hotkey combo to test.

@freak: Could the SendMessages be wrapped to a PB command, e.g. SetWindowHotkey() or such? (on windows, anyway. dunno from other OS's)

Posted: Sun Aug 16, 2009 7:09 am
by horst
freak wrote:Get/SetGadgetState() can be used on the gadget to get/set the current shortcut.
Why can't we have GetGadgetText() in case we would like to inform the user about the current shortcut (in a menu, tooltip or any text info)?

Posted: Sun Aug 16, 2009 12:10 pm
by akj
@ freak & netmaestro:

Thank you for your posts which has made everything so much clearer.

I see the gadget is based on the Windows Hot Key Control which until now I never knew existed.

I agree with Horst that Get/SetGadgetText() would be useful finishing touches.
I expect that SetGadgetText() would only change the gadget's text area contents without affecting the state of the ShortcutGadget().

Which PB events are raised by the gadget?

Posted: Sun Aug 16, 2009 2:26 pm
by freak
horst wrote:
freak wrote:Get/SetGadgetState() can be used on the gadget to get/set the current shortcut.
Why can't we have GetGadgetText() in case we would like to inform the user about the current shortcut (in a menu, tooltip or any text info)?
Because it wouldn't be crossplatform. OSX uses symbols to represent the keys instead of names, and these symbols are unicode characters. So an ascii program wouldn't be able to represent them in a string.

Also MenuItem() requires english Key names for the shortcut on Linux and OSX (because they have to be parsed back into OS constants actually) so if this gadget returns a language-specific text, you wouldn't be able to use it there anyway.

Re:

Posted: Tue Jun 25, 2013 1:56 pm
by Joris
freak wrote:
horst wrote:Why can't we have GetGadgetText() in case we would like to inform the user about the current shortcut (in a menu, tooltip or any text info)?
Because it wouldn't be crossplatform. OSX uses symbols to represent the keys instead of names, and these symbols are unicode characters. So an ascii program wouldn't be able to represent them in a string.
Also MenuItem() requires english Key names for the shortcut on Linux and OSX (because they have to be parsed back into OS constants actually) so if this gadget returns a language-specific text, you wouldn't be able to use it there anyway.
How does PB itself then write shortcut-key-text like in the Preferences Shortcut Tab ?
I would like to get that but it probably needs the API way then, or not (here on XP) ?

Thanks.