Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-12-2003, 01:26 PM   PM User | #1
meandmymachine
New to the CF scene

 
Join Date: Apr 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
meandmymachine is an unknown quantity at this point
How do I link arrow keys to code in VB.NET?

Hello there

I'm trying to write code that responds to the user manipulating two of the arrow keys (you know, the four keys just under the delete, end and page down keys). The following code compiles okay but it doesn't do anything. I just wondered how I should modify it. All contributions gratefully accepted.

meandmymachine

Heres the code:

Dim vbKeyRight As Integer
Dim vbKeyLeft As Integer

Private Sub KeyPress1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
If KeyCode = vbKeyRight Then
MsgBox("Right Key Pressed!")
End If
End Sub

Private Sub KeyPress2_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
If KeyCode = vbKeyLeft Then
MsgBox("Left Key Pressed!")
End If
End Sub
meandmymachine is offline   Reply With Quote
Old 07-12-2003, 08:10 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
You shouldn't have to declared vbKeyRight and vbKeyLeft if they are constants... How about changing it to:

Private Sub KeyPress1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
MsgBox(KeyCode)
End Sub

Then press the arrow keys and see what you get, that should give you the keycode for it.

If that doesn't work you could use DirectInput. You'd have to if you want to be able to process multiple keys at the same time.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 10-19-2009, 10:16 AM   PM User | #3
xbrem19
New to the CF scene

 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
xbrem19 is an unknown quantity at this point
I put mentioned code into VB editor pressed "play" and nothing happened. What is wrong?
M.
xbrem19 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:17 PM.


Advertisement
Log in to turn off these ads.