Capture Global Key Pressed
-
Hi all, Is there a way I can capture the keys that are being pressed without making use of an EventHandler. Maybe some old schoold C method or something? :confused: Many thanks in advance. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
Hi all, Is there a way I can capture the keys that are being pressed without making use of an EventHandler. Maybe some old schoold C method or something? :confused: Many thanks in advance. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
Try using Google for a 'low level global keyboard hook', some articles exist on CodeProject as well, so you can even begin here. I totally didn't understand the part about not making use of an EventHandler.
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
Try using Google for a 'low level global keyboard hook', some articles exist on CodeProject as well, so you can even begin here. I totally didn't understand the part about not making use of an EventHandler.
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
EliottA wrote:
I totally didn't understand the part about not making use of an EventHandler
I was referring to something like
KeyPressEventHandler
... and only making use of a method to get the last key pressed. For example:public Form1() { // Create a TextBox control. TextBox tb = new TextBox(); this.Controls.Add(tb); tb.KeyPress += new KeyPressEventHandler(keypressed); } private void keypressed(Object o, KeyPressEventArgs e) { // The keypressed method uses the KeyChar property to check // whether the ENTER key is pressed. // If the ENTER key is pressed, the Handled property is set to true, // to indicate the event is handled. if (e.KeyChar == (char)Keys.Return) { e.Handled = true; } }
Thanks for the info. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
EliottA wrote:
I totally didn't understand the part about not making use of an EventHandler
I was referring to something like
KeyPressEventHandler
... and only making use of a method to get the last key pressed. For example:public Form1() { // Create a TextBox control. TextBox tb = new TextBox(); this.Controls.Add(tb); tb.KeyPress += new KeyPressEventHandler(keypressed); } private void keypressed(Object o, KeyPressEventArgs e) { // The keypressed method uses the KeyChar property to check // whether the ENTER key is pressed. // If the ENTER key is pressed, the Handled property is set to true, // to indicate the event is handled. if (e.KeyChar == (char)Keys.Return) { e.Handled = true; } }
Thanks for the info. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
Well the keypress is an event (as is keydown and keyup) so you would need an
event handler
tohandle
theevent
. :-D As for a global keyboard hook, see my above advice as to how tohandle
thoseevents
. :cool: PS instead of casting to a char you could test the condition by doingif (e.Keycode == Keys.Enter)
e.Handled = true;check out the Keys Enumeration[^]
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
Well the keypress is an event (as is keydown and keyup) so you would need an
event handler
tohandle
theevent
. :-D As for a global keyboard hook, see my above advice as to how tohandle
thoseevents
. :cool: PS instead of casting to a char you could test the condition by doingif (e.Keycode == Keys.Enter)
e.Handled = true;check out the Keys Enumeration[^]
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]