❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
Hi.
I'm very new to C# and WinForms, I'm actually a Dart developer.
I'm trying to create some sort of stopwatch, where the program will always be on top of all the other programs, but will not have focus, and when the user press TAB it will start or reset the stopwatch.
Here's what I found during my research:
I have found a code that apparently fetch my tab key even if the program does not have focus.
But I do not have any idea of where to put it in my existing code.
But I do not have any result :/
7 Replies
I don't think you want that code. Its just a check to see if tab key is pressed when you run that code
Oh
You can use RegisterHotKey (https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey) I guess
Although TAB is definitely a weird hotkey
and probably reserved?
I have some override to detect the tabkey:
@LLVM Do I have to import user32.dll to use the hotkeys ?
RegisterHotKey? Yes.
Where should I use the
RegisterHotKey(Handle, 1, HotKey.FsModifiers.None, Keys.Tab);
?
Should I just put it directly in the main ?
Ok, it seem that I can put it as soon as I have a the windows Handle, so I put it here:
Now, how I can call a function when the hotkey is being pressed ?Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.