By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,088 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

No arrow keys ?

P: n/a
Rob
If I use the following code:

Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

Dim myKey As Integer

myKey = e.KeyValue
MsgBox(myKey.ToString)

End Sub

all of my keyboard input is displayed in the MsgBox,
However if I use any of the arrow keys the KeyDown
event handler no longer works ! All keyboard input is
no longer displayed in the MsgBox and the handler no
longer works. How can I rewrite the code to handle
arrow key input. Using Microsoft Development
Environment 2002 Version 7.0.9955
Mar 24 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Rob" <rl*****@worldnet.att.net> schrieb
If I use the following code:

Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

Dim myKey As Integer

myKey = e.KeyValue
MsgBox(myKey.ToString)

End Sub

all of my keyboard input is displayed in the MsgBox,
However if I use any of the arrow keys the KeyDown
event handler no longer works ! All keyboard input is
no longer displayed in the MsgBox and the handler no
longer works. How can I rewrite the code to handle
arrow key input. Using Microsoft Development
Environment 2002 Version 7.0.9955

Are there controls on the form? Which control has the focus when you press
the arrow key?
Armin

Mar 25 '06 #2

P: n/a
Rob
Yes, there are 2 controls on the form. The form
contains a read only Text Box and a Button. Neither
control has a Tab stop. I want to use the
arrow keys to direct a cursor. The cursor is drawn
on the desktop by means of a C++ DLL.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:eA**************@TK2MSFTNGP12.phx.gbl...
"Rob" <rl*****@worldnet.att.net> schrieb
If I use the following code:

Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

Dim myKey As Integer

myKey = e.KeyValue
MsgBox(myKey.ToString)

End Sub

all of my keyboard input is displayed in the MsgBox,
However if I use any of the arrow keys the KeyDown
event handler no longer works ! All keyboard input is
no longer displayed in the MsgBox and the handler no
longer works. How can I rewrite the code to handle
arrow key input. Using Microsoft Development
Environment 2002 Version 7.0.9955

Are there controls on the form? Which control has the focus when you press
the arrow key?
Armin

Mar 25 '06 #3

P: n/a
Hello, Rob,

That's interesting. It happens to me too. (And it clearly doesn't have
anything to do with the DLL, since I don't have this.)

I don't know if this is of any use, but I've noticed that it only
happens when the button has the focus. (It will happen continuously if
you set the TextBox's Enabled property to False, and not at all if the
Button's Enabled property is False. )

Rather mysterious. Sorry I don't know the answer -- hope someone does.

Cheers,
Randy
Rob wrote:
Yes, there are 2 controls on the form. The form
contains a read only Text Box and a Button. Neither
control has a Tab stop. I want to use the
arrow keys to direct a cursor. The cursor is drawn
on the desktop by means of a C++ DLL.

Mar 25 '06 #4

P: n/a
Hi there , I'm shadi
and have use you'r code the same way you write it & it worked good even
with the arrow keys
findout if there any evant depending on the arrow keys , if there any
elemantes on you form or other functions are using this keys

Mar 25 '06 #5

P: n/a
"Rob" <rl*****@worldnet.att.net> wrote in
news:OP**************@TK2MSFTNGP10.phx.gbl:
If I use the following code:

Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

Dim myKey As Integer

myKey = e.KeyValue
MsgBox(myKey.ToString)

End Sub

all of my keyboard input is displayed in the MsgBox,
However if I use any of the arrow keys the KeyDown
event handler no longer works ! All keyboard input is
no longer displayed in the MsgBox and the handler no
longer works. How can I rewrite the code to handle
arrow key input. Using Microsoft Development
Environment 2002 Version 7.0.9955

With controls, you can get them to respond to the navigation keys by
deriving your own class and overriding IsInputKey:

Public Class Class1
Inherits Button

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Right Then Return True
Return MyBase.IsInputKey(keyData)
End Function

End Class

Now, if you use a class1, it will trap the right arrow key in the keydown
event. However it won't move focus on to the next control anymore.
You can try this with a derived form, but it wont work. I'd guess that it
would break the navigation keys for all the controls on the form.

You could still trap it in a form by overriding wndproc :

Public Event RightArrowAlarm As EventHandler
Private Const VK_RIGHT = &H27
Private Const WM_KEYDOWN As Integer = &H100

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
If m.Msg = WM_KEYDOWN Then
If m.WParam = VK_RIGHT Then
RaiseEvent RightArrowAlarm(Me, New EventArgs)
End If
End If
MyBase.WndProc(m)
End Sub
Mar 26 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.