-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Settings/Run] LowLevel Keyboard hooking for Hotkeys #3825
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HotkeyManager(); | ||
~HotkeyManager(); | ||
|
||
HOTKEY_HANDLE RegisterHotkey(Hotkey ^ hotkey, HotkeyCallback ^ callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why are we using a ^? Is it because of interop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ^ character means a CLR pointer. This is because this is not standard C++ but rather C++/CLI. It just means a reference to a garbage collected (managed) object.
Yet to look at the code, but I observed some things while testing:
|
The change affects the hotkey control for FZ as well, so we should loop in @enricogior. With this change users can enter windows shortcuts as well, however since the FZ hotkey works using the RegisterHotkey API those won't work. |
I'll let Arjun approve this as he has more context.
I think the off center issue is because of xaml islands. Not sure if it is related to this PR. @somil55 thoughts? |
Hi @arjunbalgovind |
@arjunbalgovind
"windows shortcuts" you mean generic win+key or "existing windows shortcut" that will be processed by the system and not passed to FZ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the hook logic looks good. Not entirely sure what causes the weird interactions between launcher and low level hooks, it could be Xaml Islands as Alekhya mentioned so maybe we should validate if it still happens after moving to WPF.
handle |= hotkey->Win << 8; | ||
handle |= hotkey->Ctrl << 9; | ||
handle |= hotkey->Shift << 10; | ||
handle |= hotkey->Alt << 11; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] these can be constants rather than hardcoded numbers.
src/common/interop/KeyboardHook.cpp
Outdated
hookHandle = SetWindowsHookEx( | ||
WH_KEYBOARD_LL, | ||
(HOOKPROC)(void*)Marshal::GetFunctionPointerForDelegate(hookProc), | ||
GetModuleHandle(msclr::interop::marshal_as<std::wstring>(curModule->ModuleName).c_str()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we cant pass in NULL like we do in existing code where we use SetWindowsHookEx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at the documentation more closely, I think you are right, this should be set to null since the hook procedure is within the process and not in a different dll. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa
I meant existing windows shortcuts. Like if a user tries to set it to Win+Space or something like that. It was like this earlier as well, but before you couldn't even enter Win+Space so a user would never run into that problem. |
@arjunbalgovind |
|
I don't think that behavior is intended, I'll fix that |
5ccfceb
to
e5c330a
Compare
d56ad08
to
3b5e07e
Compare
@enricogior |
@htcfreek, this PR will fix the Win+ shortcuts case allowing you to enter it, but FZ currently does not support using existing windows shortcuts. We currently do not support a single key (like Esc) for the hotkey input, but we might add that in the future. Agreed that we should put a better error message than just displaying "Undefined". The changes from this PR will be included in 0.19. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally. For some reason when I open Run the first time with Alt+Space the text box doesn't have focus so I need to click inside it. It could be from the stealing focus logic, and that doesn't seem to fix the start menu interaction either, so I think the stealing focus logic can be reverted and we'll work on the start menu interaction thing separately since it wasn't directly related to your PR.
@traies can we get this merged in? lotta tweaks and i know you're getting ramped off |
3b5e07e
to
bf89bbe
Compare
I removed the commit that tried to fix the focus issues that @arjunbalgovind mentioned because they weren't fixing the problem. I also rebased to master and checked it is building the installer properly now. As for the focus issues, I think it would probably be best if it is spun out to another PR. As it currently stands for this PR, trying to hit the shortcut to bring up the Launcher prompt while having the start menu open causes the focus to be kept by the start menu. This only happens when launching the solution from runner, and not when launching the PowerLauncher executable directly, for some reason. |
@somil55 shall we merge this in? There is already an issue to track the start menu focus problem so we could reprioritize that. Users earlier observed it when they used KBM to remap Win+R to Alt+Space and open Launcher, and it happens now with these low level hook changes as well. |
lets get this merged in here, |
@arjunbalgovind Sure! |
@ryanbodrug-microsoft can we merge this in? These are the things that we need to check after fixing:
|
In reality now that we removed islands, It should work much lower. The issue then becomes the dual settings work which it pretty costly from a resource stance. |
Summary of the Pull Request
Replaced use of
NHotkey.Wpf
with low level keyboard hooks for both Settings and Run.References
PR Checklist
Detailed Description of the Pull Request / Additional comments
NHotkey
nuget package.interop
library, which can be used to register callbacks for Key Presses using low level hooking.Validation Steps Performed