Ian Branch 128 Posted September 3, 2019 Hi Team, D10.3.2 not that it probably makes any difference.  If I have two Apps with the same HotKey but doing different things, it is only the first App loaded that the HotKey works for, doesn't matter if the second App has focus or not. 😞 So - Two questions... 1. Is there any way to make a HotKey effective only for the App in focus? 2. If an App has several forms, is there any way to have the HotKey work for only the form in focus? Regrettably my suspicion in both cases is No, It's a Windows thing, however I am ready, willing and able to be pleasantly surprised. 😉  Regards & TIA, Ian Share this post Link to post
Remy Lebeau 1436 Posted September 4, 2019 (edited) If you are referring to the Win32 RegisterHotKey() function and WM_HOTKEY window message, then such hotkeys are system-wide and any given hotkey can only be registered for one window at a time. To use the same hotkey with multiple processes at the same time, you will have to resort to using a global keyboard hook and handle the keystrokes manually. Edited September 4, 2019 by Remy Lebeau Share this post Link to post
Ian Branch 128 Posted September 4, 2019 Hi Remy, Thanks for your input. >> you will have to resort to using a global keyboard hook and handle the keystrokes manually. Not my area of expertise I'm afraid. Can you point me to some examples pls? Regards, Ian Share this post Link to post
Tom F 85 Posted September 4, 2019 Hey, I'm far, far from an expert on these matters so my thinking may be very flawed here. But when app #2 gains focus, perhaps it could send a message (and wait for a response) to app #1 telling it to de-register the hotkey? And then app #2 registers the hot key.  And same for when app #1 gains focus, it messages and waits for app #2 to de-register the hotkey. Share this post Link to post
Remy Lebeau 1436 Posted September 4, 2019 14 hours ago, Tom F said: Hey, I'm far, far from an expert on these matters so my thinking may be very flawed here. But when app #2 gains focus, perhaps it could send a message (and wait for a response) to app #1 telling it to de-register the hotkey? And then app #2 registers the hot key.  And same for when app #1 gains focus, it messages and waits for app #2 to de-register the hotkey. That's fine if you control both apps. But what if you want to use a hotkey that is used by another app that you don't control? Then you are SOL. This is why apps are supposed to pick unique hotkeys for themselves, or allow the user to configure the hotkeys (see the VCL's THotKey component and TextToShortCut() function). 1 Share this post Link to post
Ian Branch 128 Posted September 4, 2019 Hi Remy, Tom, As I suspected, and Remy so eloquently expressed, I am SOL. This came to light in my own testing when I implemented a HotKey in the App, went to test it and my AV popped up. WTH! The Apps themselves use many HotKeys. Perhaps I need to move them to a Menu/Submenu scenario. Will think on it.  Thanks to you both for your inputs. Regards, Ian Share this post Link to post
Attila Kovacs 631 Posted September 4, 2019 It's easy. If those hotkeys are really app-wide hotkeys and not a case for menu/action components, just hook the application messages and evaluate WM_KEYDOWN. VCL does the same. For every single menu/action visible. Every single time you press a key in your app. Share this post Link to post
Remy Lebeau 1436 Posted September 6, 2019 On 9/4/2019 at 3:03 PM, Attila Kovacs said: VCL does the same. For every single menu/action visible. Every single time you press a key in your app. Yup, see A Key’s Odyssey for more details about that. Share this post Link to post