keyboard event listener
-
i have win form and i have registered keyboard event for it but it doesn't work //////////////////////// this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); //////////////////////// private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.KeyValue.ToString()); } //////////////////////// but when i press any key on my keyboard, i doesn't recieve any thing. thnx in advance
-
i have win form and i have registered keyboard event for it but it doesn't work //////////////////////// this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); //////////////////////// private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.KeyValue.ToString()); } //////////////////////// but when i press any key on my keyboard, i doesn't recieve any thing. thnx in advance
i recieve nothing..... thnx
-
i have win form and i have registered keyboard event for it but it doesn't work //////////////////////// this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); //////////////////////// private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.KeyValue.ToString()); } //////////////////////// but when i press any key on my keyboard, i doesn't recieve any thing. thnx in advance
If another
Control
has the focus (and it most likely does), you won't receive keyboard events. You have to setForm.KeyPreview
to true. Then you should have better results.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
If another
Control
has the focus (and it most likely does), you won't receive keyboard events. You have to setForm.KeyPreview
to true. Then you should have better results.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
but i wanna listen to more than one key like "ctrl+h" or like this
-
but i wanna listen to more than one key like "ctrl+h" or like this
As far as text in your console app go, you can use the
Console.In
properties (aTextReader
) to grab typeable characters like "h". When you get input like this, call theGetKeyState
method (after P/Invoking it, of course) to determine whether or not a modifier key is pressed.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----