Anyway to query hot keys?
Anyway to query hot keys?
I am writing a portion of a larger app... Timezone & language is getting in the way...
On entry into a field, if possible, I need to add some hotkeys; but if those hotkeys are already taken, I need to "push them" down and restore them when field losses focus...
is there anyway to query PB if a hotkey is present and what it is? or use windows api? It's a windows app only so I do not need cross platform...
On entry into a field, if possible, I need to add some hotkeys; but if those hotkeys are already taken, I need to "push them" down and restore them when field losses focus...
is there anyway to query PB if a hotkey is present and what it is? or use windows api? It's a windows app only so I do not need cross platform...
Re: Anyway to query hot keys?
On Windows, if you can try to register a hotkey using the api call RegisterHotKey. If it fails (returns 0), it means another program is already using the requested key combination. You can see my post regarding global windows hotkeys for an example of using that api call here:
http://www.purebasic.fr/english/viewtop ... 12&t=61117
If by "push them down", you mean you want to use a hotkey even though another program is already using it, maybe you can set up a keyboard hook to intercept the key combination. If you don't want the other program to receive the key presses, just don't pass on the message. See my keyboard hook example here:
http://www.purebasic.fr/english/viewtop ... 14&t=61154
http://www.purebasic.fr/english/viewtop ... 12&t=61117
If by "push them down", you mean you want to use a hotkey even though another program is already using it, maybe you can set up a keyboard hook to intercept the key combination. If you don't want the other program to receive the key presses, just don't pass on the message. See my keyboard hook example here:
http://www.purebasic.fr/english/viewtop ... 14&t=61154
Re: Anyway to query hot keys?
Let's say the application has "CTRL-D" assigned to #menuDeleteItem
When entering a specific field, I want ctrl-d to be assigned to #menuDebugOn, on exit, I want to return to #menuDeleteItem.
so I want to
On Focus:
oldmenu = QueryKeyboardShortcut(#MyWindow,#pb_shortcut_control|#pb_shortcut_d)
AddKeyboardShortcut(#MyWindow,#pb_shortcut_control|#pb_shortcut_d, #menuDebugOn)
On LostFocus
AddKeyboardShortcut(#mywindow,#pb...., oldmenu)
When entering a specific field, I want ctrl-d to be assigned to #menuDebugOn, on exit, I want to return to #menuDeleteItem.
so I want to
On Focus:
oldmenu = QueryKeyboardShortcut(#MyWindow,#pb_shortcut_control|#pb_shortcut_d)
AddKeyboardShortcut(#MyWindow,#pb_shortcut_control|#pb_shortcut_d, #menuDebugOn)
On LostFocus
AddKeyboardShortcut(#mywindow,#pb...., oldmenu)
Re: Anyway to query hot keys?
Oh, okay. I misunderstood. If you did already know that Ctrl+D is for #menuDeleteItem, you can just overwrite a keyboard shortcut when your text field gets focus, and then overwrite that again with another call to AddKeyboardShortcut on LostFocus without having to first call RemoveKeyboardShortcut, but I don't know how to tell if a keyboard shortcut added with AddKeyboardShortcut already exists.
Re: Anyway to query hot keys?
Hi jassing
Search the forum for hot keys by DarkPlayer
If I can get some free time maybe I can help
Search the forum for hot keys by DarkPlayer
If I can get some free time maybe I can help
Egypt my love
Re: Anyway to query hot keys?
Thanks Rashad, but sadly that search pulled up no results.
but knowing there's an answer means I'll keep digging. thank you!
-josh
but knowing there's an answer means I'll keep digging. thank you!
-josh
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Anyway to query hot keys?
Code by Dark Player in this post: http://www.purebasic.fr/english/viewtop ... ys#p326431
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Anyway to query hot keys?
I will print & read that thread out.. On 1st pass; I don't see how to query if a hotkey already exists and what it is... I'm missing something...
thanks
thanks
Re: Anyway to query hot keys?
Can you submit a little example to show us what do you mean by (Fields)
Is it ListIcon fields or StringGadget or any other method ?
It will be very helpful for us
Is it ListIcon fields or StringGadget or any other method ?
It will be very helpful for us
Egypt my love
Re: Anyway to query hot keys?
Anything... Actually; it shouldn't matter... you assign AddKeyboardShortcut() to a window, not a gadget, Just want to find out (if any) pre-exist so I can reset them once I am done.RASHAD wrote:Can you submit a little example to show us what do you mean by (Fields)
Is it ListIcon fields or StringGadget or any other method ?
It will be very helpful for us
Another way to think about it is I want to, while in 1 string gadget, temporarily override any existing keyboard shortcuts assigned to the window .
the specificness of it is a StringGadget, using EventType focus & lostfocus to set & reset the hot key
I can do a keyboard hook/callback; but I was just trying to make it as simple as possible for when I hand it off.
Here's just a quick idea
Code: Select all
OpenWindow(0,1,1,300,100,"")
StringGadget(0,1,1,50,20,"")
StringGadget(1,1,30,50,20,"")
AddKeyboardShortcut(0,#PB_Shortcut_A,0)
Declare StringGadget1()
Repeat
Select WaitWindowEvent(100)
Case #PB_Event_Gadget
Select EventGadget()
Case 1 : StringGadget1()
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 0: Debug "for any other field"
Case 1: Debug "Only for gadget #1"
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
; Imagine I know nothing about the above.... someone else wrote it and I can't change it or talk to them.
Procedure StringGadget1()
Select EventType()
Case #PB_EventType_Focus
; here I want to query/store anything assigned to window #0, shortcut key #pb_shortcut_a so I can restore it later.
AddKeyboardShortcut(0,#PB_Shortcut_A,1)
Case #PB_EventType_LostFocus
; Suppose I don't know anything above 5
; here I want to restore the A to menu event 0.
EndSelect
EndProcedure
-
- User
- Posts: 49
- Joined: Wed Dec 17, 2014 11:54 am
Re: Anyway to query hot keys?
Code: Select all
OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)
If RegisterHotKey_(WindowID(0),0,#MOD_ALT,#VK_F4)=0
Debug "The Alt+F4 hotkey is in use"
EndIf
Re: Anyway to query hot keys?
Try it -- before calling RegisterHotKey_() issue:PB Fanatic wrote:Code: Select all
OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible) If RegisterHotKey_(WindowID(0),0,#MOD_ALT,#VK_F4)=0 Debug "The Alt+F4 hotkey is in use" EndIf
AddKeyboardShortcut(#Window_0,#PB_Shortcut_Alt|#PB_Shortcut_F4,120)
When you run registerhotkey_() it returns 1
So, you don't know:
A) that was previously defined
B) that the previous shoftcut was set to menu item 120
-
- User
- Posts: 49
- Joined: Wed Dec 17, 2014 11:54 am
Re: Anyway to query hot keys?
jassing wrote:Try it -- before calling RegisterHotKey_() issue:
AddKeyboardShortcut(#Window_0,#PB_Shortcut_Alt|#PB_Shortcut_F4,120)
When you run registerhotkey_() it returns 1
Code: Select all
OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)
AddKeyboardShortcut(0,#PB_Shortcut_Alt|#PB_Shortcut_F4,120)
result=RegisterHotKey_(WindowID(0),0,#MOD_ALT,#VK_F4)
Debug result ; 0
If result=0
Debug "The Alt+F4 hotkey is in use"
EndIf
Re: Anyway to query hot keys?
The api function RegisterHotkey and PB's addkeyboardShortcut do two different things. You cannot use the success or failure of a call to RegisterHotkey to determine if the same keys were already used with AddKeyboardShorcut.
You can exclusively use RegisterHotkey instead of AddKeyboardShortcut and use code like DarkPlayer's to determine if a hotkey exists but since hotkeys are system-wide this can get messy. For example, the ability to register the hotkey Ctrl+D will vary from computer to computer because different software that may be installed might already be using it.
AddKeyboardShortcut creates a Keyboard Accelerator not a Hotkey. These shortcuts should work in your program no matter what. Your program has an accelerator table that stores these shortcuts. You can copy it with CopyAcceleratorTable. Once copied, iterate through the items in a loop to see if your shortcut already exists. You can change it if you like (still editing the copy), then destroy the old accelerator table and register the copy as a new one. See the msdn page here: http://msdn.microsoft.com/en-us/library ... itable_acc
You can exclusively use RegisterHotkey instead of AddKeyboardShortcut and use code like DarkPlayer's to determine if a hotkey exists but since hotkeys are system-wide this can get messy. For example, the ability to register the hotkey Ctrl+D will vary from computer to computer because different software that may be installed might already be using it.
AddKeyboardShortcut creates a Keyboard Accelerator not a Hotkey. These shortcuts should work in your program no matter what. Your program has an accelerator table that stores these shortcuts. You can copy it with CopyAcceleratorTable. Once copied, iterate through the items in a loop to see if your shortcut already exists. You can change it if you like (still editing the copy), then destroy the old accelerator table and register the copy as a new one. See the msdn page here: http://msdn.microsoft.com/en-us/library ... itable_acc
Re: Anyway to query hot keys?
Sorry for not using the proper term...
Is there a way to query pre-existing calls to AddKeyboardShortut() and determine what they are (menu #)?
Is there a way to query pre-existing calls to AddKeyboardShortut() and determine what they are (menu #)?