how to override IsInputKey(..) function?

S

Steve

I would like to override the IsInputKey function in order
to trap the arrow up/down keys in the Key Events. I
understand that arrow keys don't have a char
representation and thus, hard to trap. Someone wrote this
override for IsInputKey in C# which apparently worked, and
I tried to convert it to VB.Net but not working. Here is
the C# version and following - my conversion. It would be
great if anyone out there knows how to do this correctly.
Do I need to import/inherit anything? Error says my
override version has different access level than the
original IsInputKey.

C# version (article at
http://www.dotnet247.com/247reference/msgs/2/14108.aspx)

const char myLeft = (char)252;
const char myRight = (char)253;
const char myUp = (char)254;
const char myDown = (char)255;

protected override bool IsInputKey(Keys key) {
switch (key) {
case Keys.Left:
OnKeyPress(new KeyPressEventArgs(myLeft));
return true;
case Keys.Right:
OnKeyPress(new KeyPressEventArgs(myRight));
return true;
case Keys.Up:
OnKeyPress(new KeyPressEventArgs(myUp));
return true;
case Keys.Down:
OnKeyPress(new KeyPressEventArgs(myDown));
return true;
default:
return base.IsInputKey(key);
}
}

My Version in VB.Net

Const myLeft = Chr(37)
Const myRight = Chr(39)
Const myUp = Chr(38)
Const myDown = Chr(40)

Overrides Function IsInputKey(ByVal key As Keys) As Boolean
Select Case key
Case Keys.Left
OnKeyPress(New KeyPressEventArgs(myLeft))
Return True
Case Keys.Right
OnKeyPress(New KeyPressEventArgs(myRight))
Return True
Case Keys.Up
OnKeyPress(New KeyPressEventArgs(myUp))
Return True
Case Keys.Down
OnKeyPress(New KeyPressEventArgs(myDown))
Return True
Case Else
Return True
End Select
End Function
 
D

Dominique Vandensteen

instead of using KeyPress event, have a look at KeyUp event
that one is raised just after keypress and holds the keycode in het
eventArgs
there you can check for special keys (esc, arrows, function keys,...)


Dominique
 

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

Top