No arrow keys ?

R

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
 
A

Armin Zingler

Rob said:
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
 
R

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.
 
R

R. MacDonald

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
 
S

shadi.al.rashid.shush

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
 
H

hoppy

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
 

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