Hotkey gadgets would be nice!

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

netmaestro wrote:For the font just look up a few posts... :wink:
Thanks, haven't seen that :roll:
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 »

Michael Vogel wrote:...is there also a possibility to check combinations including the Windows key (#VK_MOD)?
MSDN re: HKM_GETHOTKEY wrote:Returns the virtual key code and modifier flags. The virtual key code is in the low-order byte, and the modifier flags are in the high-order byte. The modifier flags can be a combination of the following values:

Value.......................Meaning

HOTKEYF_ALT...........ALT key
HOTKEYF_CONTROL..CONTROL key
HOTKEYF_EXT...........Extended key
HOTKEYF_SHIFT........SHIFT key
VK_MOD isn't one of the modifiers returned, so I'd say not. Surely there are more than enough available combinations without it, don't you think?
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

netmaestro wrote:...more than enough..., don't you think?
I never can have enough! :lol:

___
the following lines have absolute nothing to do with the thread, but however...

PS I still can remember when someone thought to start the video memory area at 640k, because below that everyone would have enough main memory :wink:

PSS my PET had 8K (!) memory at this time and a simple IBM PC with 64K memory and 10MB hard disk did cost more than 10.000 Euro/$ :shock:
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 »

IBM PC with 64K memory and 10MB hard disk did cost more than 10.000 Euro/$
Gotcha! No such thing as euros when they sold those... hehe :D
BERESHEIT
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re:

Post by UserOfPure »

Hi netmaestro, I was looking at your hotkey code above and it's great that it returns the text string, which means I can store it in my INI file nicely, but how would I turn that string back into flags for use with the RegisterHotkey API? I can get the mods easily enough (just a FindString for "Shift +" etc) but the last part (the non-mod key) stumps me... for example, if it's just the letter A, or what if it's the the Break key? Is there an easy way to determine that final part of non-mod key without doing a whole If/ElseIf block? I think it may be to do with the GetKeyNameText API but not sure.
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: Hotkey gadgets would be nice!

Post by kernadec »

hello

thank you, very nice

there is a hotkey forum here: http://www.autohotkey.com/forum/

bye
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Hotkey gadgets would be nice!

Post by UserOfPure »

That forum is for the AutoHotKey application, and doesn't directly help with netmaestro's code above.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Re:

Post by Trond »

UserOfPure wrote:Hi netmaestro, I was looking at your hotkey code above and it's great that it returns the text string, which means I can store it in my INI file nicely, but how would I turn that string back into flags for use with the RegisterHotkey API? I can get the mods easily enough (just a FindString for "Shift +" etc) but the last part (the non-mod key) stumps me... for example, if it's just the letter A, or what if it's the the Break key? Is there an easy way to determine that final part of non-mod key without doing a whole If/ElseIf block? I think it may be to do with the GetKeyNameText API but not sure.
Better just store the hotkey number as a string. Use Str(wHotkey). To get it back, just use Val() on the string.
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Re:

Post by UserOfPure »

I am storing it as a string, as I said (the INI file comment). But when I read it back, the RegisterHotKey API doesn't take a string, but a virtual key code. So if the hotkey is Ctrl + Break, how do you make the Break key value (#VK_CANCEL) work with Val()? Now you see the problem. :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Re:

Post by Trond »

UserOfPure wrote:I am storing it as a string, as I said (the INI file comment). But when I read it back, the RegisterHotKey API doesn't take a string, but a virtual key code. So if the hotkey is Ctrl + Break, how do you make the Break key value (#VK_CANCEL) work with Val()? Now you see the problem. :)
No, you didn't read what I wrote. Use Str() on the keycode. Don't use GetHotkeyText().
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Hotkey gadgets would be nice!

Post by netmaestro »

I'm currently using this code for translating the contents of a hotkey control into something usable with RegisterHotkey_():

Code: Select all

Global NewMap MapModifier()
MapModifier(Str(#HOTKEYF_ALT))     = #MOD_ALT
MapModifier(Str(#HOTKEYF_CONTROL)) = #MOD_CONTROL
MapModifier(Str(#HOTKEYF_SHIFT))   = #MOD_SHIFT


Procedure SetHotkey(HotKey.w)
  Protected mod, key
  mod = MapModifier(Str(HotKey>>8)) : key = HotKey & $FF
  hID = GlobalAddAtom_("QuickSnap HotKey")
  ProcedureReturn RegisterHotKey_(WindowID(#wMain), hID, mod, key)
EndProcedure

; [...]
  Case #gPref_SetHotKey
    thisHotkey.w = SendMessage_(hwndHot, #HKM_GETHOTKEY, 0, 0) 
    If HotkeyIsValid(GetHotkeyText(thisHotkey))
      If SetHotkey(thisHotkey)
;       [...]
PB 4.40 of course, as I'm using a map. Hope it's helpful!
BERESHEIT
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Hotkey gadgets would be nice!

Post by UserOfPure »

Thanks for both of you replying, but I'm nowhere near understanding. If my INI file saves the hotkey like this:

Code: Select all

apphotkey = Ctrl + Shift + F1
Then how do I read that and turn it into something that RegisterHotKey can use? Okay, ignore the mods, because that's easy, and we're left with "F1". How would my app know that the text "F1" = #VK_F1? I don't want to store it as a raw keycode because it's not user-friendly. I want it stored as plain text like the above. It seems to me that the only way is to do a whole bunch of If/Then to check every text scenario. Surely there's an API call that can convert "F1" to #VK_F1? I've tried GetKeyNameText and MapVirtualKey without success so far.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Hotkey gadgets would be nice!

Post by netmaestro »

Application_Hotkey_Code =
Application_Hotkey_FriendlyName =
BERESHEIT
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Hotkey gadgets would be nice!

Post by UserOfPure »

Still no good because I want to be able to edit the INI file manually with the hotkey, which is the reason for it being stored friendly. No problem, I can just do a comparison block of code after all. It won't be too hard, it's just time-consuming and boring to write. :mrgreen:
Post Reply