GetKeyState() for c#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I need to check and see if a Tab key was pressed. I found GetKeyState() but
that only seems to be for Visual Basic. Is there anything like it for c#?
(GetKeyName didn't seem too promising when I looked over it.)
Thanks!
Melanie
 
Melanie,

Why not just use the KeyDown event? It will give you a value indicating
the key that was pressed, and any modifiers that were pressed as well (this
includes firing if the Tab key is hit).

Hope this helps.
 
I'm not sure what's going on, but I've tried:

if (Control.ModifierKeys == Keys.Tab) {MessageBox.Show("Tab");}

if (e.KeyCode == Keys.Tab){MessageBox.Show("Tab");}
(this works for everything (up/down) but Tab)

as well as some code that I found from someone elses question:

"for each control that do not catch TAB key, override IsInputKey method like
following :
protected override bool IsInputKey(Keys keyData) {
if (keyData==Keys.Tab) return true;
return base.IsInputKey (keyData);
}
Now, KeyDown event will be called if TAB key is pressed."

and nothing has worked, although I'm not sure I completely did the 3rd
option correctly. (can you just put the protected override bool at the
beginning of the program or do you somehow connect it with each textbox that
I'd tab out of?)

Any suggestions????

Very frustrated,
Mel
 
I'm not sure what's going on, but this is what I've tried:

if (e.KeyCode == Keys.Tab){MessageBox.Show("Tab");}
(this works for everything but the Tab key (up/down are ok))

if (Control.ModifierKeys == Keys.Tab){MessageBox.Show("Tab");}

as well something I found online that answered someone elses question:

"for each control that do not catch TAB key, override IsInputKey method like
following :
protected override bool IsInputKey(Keys keyData) {
if (keyData==Keys.Tab) return true;
return base.IsInputKey (keyData);
}
Now, KeyDown event will be called if TAB key is pressed."

Although I'm not 100% sure I've done that one correctly (do you just put it
at the beginning of the program or do you somehow specify which textboxes use
it?)

Any suggestions???

Very frustrated,
Mel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top