key down in windows forms (C# 2.0) [modified]
-
i want to catch any key down event in my windows form. but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control. how can i catch any keydown event without referencing each control in the formular to the keydown event? another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution) _______________________ where is the "any" key? -- modified at 7:11 Wednesday 9th August, 2006
-
i want to catch any key down event in my windows form. but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control. how can i catch any keydown event without referencing each control in the formular to the keydown event? another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution) _______________________ where is the "any" key? -- modified at 7:11 Wednesday 9th August, 2006
Do you want catch just any key down or only key down when one of the child controls of your form (or the form itself) is focused?
-
Do you want catch just any key down or only key down when one of the child controls of your form (or the form itself) is focused?
-
You have to install windows hook procedure to intercept all keyboard events. Look at “How can I use 'Hooks' in .NET” article at following link http://72.14.203.104/search?q=cache:NUhXDPTnLJgJ:www.syncfusion.com/FAQ/WindowsForms/FAQ\_c70c.aspx+"DllImport"+SetWindowsHookEx+WH\_KEYBOARD+C%23&hl=en&gl=ca&ct=clnk&cd=1
-
i want to catch any key down event in my windows form. but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control. how can i catch any keydown event without referencing each control in the formular to the keydown event? another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution) _______________________ where is the "any" key? -- modified at 7:11 Wednesday 9th August, 2006
-
Do you want catch just any key down or only key down when one of the child controls of your form (or the form itself) is focused?
You can read about windows hooks in .Net here http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/[^] Use WH_KEYBOARD when installing the hook procedure with SetWindowsHookEx Use following code to detect key down in your hook static readonly int WM_KEYDOWN = 256, public Int32 KeyboardProc(int code, Int32 wParam, Int32 lParam) { if ((Int32)wParam == (Int32)WM_KEYDOWN ) { // do processing } // do not forget to call next hook !!!!!!!!!!!! // CallNextHookEx is win32 api that can be loaded to .Net // using dll import like they did with setwindowshookex in example return CallNextHookEx(hHook, code, wParam, lParam); }
-
It will work only if the the form captured the input. As far as I unerstand the goal is to catch all keyborad key downs regardless to the current window.
-
It will work only if the the form captured the input. As far as I unerstand the goal is to catch all keyborad key downs regardless to the current window.