Help Needed for ShortCutGadget()

Just starting out? Need help? Post your questions and find answers here.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Help Needed for ShortCutGadget()

Post 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.
Anthony Jordan
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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?
Anthony Jordan
freak
PureBasic Team
PureBasic Team
Posts: 5944
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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)
BERESHEIT
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post 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)?
Horst.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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?
Anthony Jordan
freak
PureBasic Team
PureBasic Team
Posts: 5944
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re:

Post 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.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply