471,084 Members | 897 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,084 software developers and data experts.

how to override IsInputKey(..) function?

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
Nov 20 '05 #1
1 6645
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
"Steve" <an*******@discussions.microsoft.com> wrote in message
news:6b****************************@phx.gbl...
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Josh Lessard | last post: by
6 posts views Thread by Angus Comber | last post: by
3 posts views Thread by programmer.py | last post: by
2 posts views Thread by win | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.