Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Controling The Mouse With Arrow Keys

Hey guys and gals,
In the lab I program control systems for there is a lot of EMF interference and i guess the lenght of the mouse cord is perfect as an antenea (if I could spell). So when everything is on they have to unplug the mouse or the computer goes haywire. So I would like to put a function to where when they depress the arrow keys it moves the mouse.
There is a lot of processing going on so I can't have a routine just sit and wait to capture it...

Also I would like the enter key on the number key board to be the select. infact using the number keyboard exclusivly was what I had in mind, 8up 2 down, 4 left.

Hoping it was independent of the other arrow keys and enter.

(they have to enter in numbers and hit return)

any help would be usefull.


(if the arrow keys are not independent I was thinking of having a function key toggle the mouse control from arrow keys with cursor to arrow keys that move the mouse)

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Controling Certain Excel Function Keys
I'm trying to write a small project to open up only certain Excel documents on a shared drive. I need to limit the user to only working with that document. I disabled the file, new, and open tools bars with this code:

For x = 1 To Application.CommandBars.Count - 1
For y = 1 To Application.CommandBars(x).Controls.Count - 1
Debug.Print Application.CommandBars(x).Controls(y).Caption
Select Case Application.CommandBars(x).Controls(y).Caption
Case "&File"
Application.CommandBars(x).Controls(y).Enabled = False
Case "&New"
Application.CommandBars(x).Controls(y).Enabled = False
Case "Open"
Application.CommandBars(x).Controls(y).Enabled = False
End Select

The Ctrl Alt + O and similar short cuts still work. How can I catch or disable them while working in the document.

Found it:

Application.OnKey "^o", ""

Application.OnKey "^o"

Arrow Keys++
Hey I was wondering how I could get input from one of the arrow keys to do an action.

Using Arrow Keys??
I'm a visual basic beginner only 15

How can i use arrow keys and/or other keys in Vb?? Is there an Inkey$ or something? Please help

The Arrow Keys?
Try as I might I can't seem tell when the arrow keys are pressed. Has anyone done this before? At this point Im looking for all the hep I can get.


Please Help, Arrow Keys
Okay, I know I must be doing something stupid.. but in the VB IDE environment at design time my arrow keys won't work. No matter what has focus when I use my arrow keys it scrolls through properties. The only way I can move the cursor around is with the mouse.. what am I doing wrong. It didnt used to do this, and my arrows still work fine in other programs.

Arrow Keys
how can i detect when an user press the Arrow Keys in a TextBox or the PAgeDown PageUp ones..

i've tried the KeyPress(Keyascii as Integer) event...

but it doesn't detect some keys like these I need...

appreciate any help.. thanx

Arrow Keys!!!
Dear friends,
i'm going to ask u a very sily question,"How to use the arrow and the 'F' keys?" Plz guide me in details.

Arrow Keys
How do I use the Arrow Keys in VB?

Arrow Keys
When I use the press key event and the ascii codes for the arrow keys, nothing happens. At first I though it was a problem with the ascii codes I had got, so I made a tiny programme that told you the ascii of all the keys you pressed when you pressed them. It worked for most of them, but not for the arrow keys. I think this is because There is something already happening for the arrow keys. Please can you tell me how to make something happen When I press the arrow keys.

UP && Down Arrow Keys VB
i'm using

Private Sub cboPartNumber_Validate(Cancel As Boolean)

so that when i press the TAB key my selection changes.

However when i use my up & down arrow my selection doesnt change.

What command do i need to use to allow the up & down arrow keys to act in the same way as my tab key using the vaildate event.


Using Arrow Keys
Im brand new to programming and trying to make a little image on the screen move, up until now ive just been using the keypad (8,6,4,2) to move the image, cuz i couldnt find the ascii numbers for the arrows. Now i have found out that there is no ascii numbers for the arrows lol. How do i use the arrow keys to move? I know i need to use keyDown??? Heres my code for using 8 6 4 2:

VB Code:
Private Sub Form_KeyPress(KeyAscii As Integer)    If tmrCarMove.Enabled = True Then        '********************************        'Move Frogger to the Right        '********************************        If KeyAscii = 54 And imgFrog.Left < 5280 Then            imgFrog.Left = imgFrog.Left + 100            Call Check                    '********************************        'Move Frogger to the Left        '********************************        ElseIf KeyAscii = 52 And imgFrog.Left > 0 Then            imgFrog.Left = imgFrog.Left - 100            Call Check                '********************************        'Move Frogger UP        '********************************        ElseIf KeyAscii = 56 Then            imgFrog.Top = imgFrog.Top - 400            Call Check                '********************************        'Move Frogger DOWN        '********************************        ElseIf KeyAscii = 50 And imgFrog.Top < 5760 Then            imgFrog.Top = imgFrog.Top + 400            Call Check        End If    End If    End Sub

Is there a simple way to change this so i can use the arrows??? Thanks!!

Arrow Keys?
Firstly Hi guys!
How do I make it so that VB 6 will recognise the arrow keys ? I mean I have no idea where to begin. All I want to do is make it so I can move a image with the arrow keys I am kinda a noob when it comes to visual basic as I have been doing it at college for 3 years but my teachers dont see the need to teach us the most basic things.... anyway any help on this would be most apprieciated...

4 Arrow Keys
i haf a problem....i am using the 4 arrow keys in the keyboard to invoke command buttons on the interface...the problem is when i click any of the arrow key, the corresponding button doesnt actually being invoked...bcuz the cursor moves on to the next nearest button and selects it....and as i keep on clicking the arrow key, the cursor keep on selecting diffrent type of command buttons...its like i am using the arrow keys to select a file i need, and then clicking enter to open the file....the command butons are invoked only if i associate shift,ctrl or alt key wif the arrow key, as in i click either of those key, hold it down and then when i press the arrow keys the command button excutes its i dont want this....i want the command button to be invoked only by pressing the arrow keys and no other associating keys...note that besides te arrow keys, if i assign the functions to other key, lets say W,A,S,D...the command button is invoked beside having to press ctrl,sift,or alt key....but i want to use my arrow please help.....

Doing Something With Arrow Keys
I need the ascii values of the arrow keys on the keyboard. I want to use the keypress event with Form1. I have several charts but none show the value. Plz Help.

Arrow Keys
Does anyone know how to get arrow keys to respond when there is more than one control on the form, I set keypreview to true and have tried setting focus to the form but that doesn't wanna work.

Using Arrow Keys In VBA...?

I am using VBA and am trying to get the arrow keys on the keyboard to activate some code.

When I press the left arrow key, I want a label (which is already on my form) to display "Left". When the right key is pressed, "Right" and so on.

I am using the VBA in MS Word, but there is no KeyPreview option for the form.

Any information about how I can get the keys to work in VBA??



Arrow Keys....
Ok... I thought I had the code to move a Command Button around the screen using the Arrow keys... but it doesn't appear to be working.

Can someone post some code for me?

Thanks in advance

Arrow Keys? (Done)
What is the ascii code for the arrow keys on the keyboard? ...

Maybe this can help:

VB Code:
Private Sub Form_KeyPress(KeyAscii As Integer)'Set CaseSelect Case KeyAsciiCase "119"'Reset Rest    intfront = -1    intright = -1    intleft = -1'Start Motion    intback = intback + 1    Image1.Top = Image1.Top - 90'Picture    Image1.Picture = imgback(intback).Picture'Check Max Pic    If intback = 8 Then    intback = -1    End If'Rest goes on for left, right, and back  

I can't get arrows to work If anyone has anything to help me out, i would really like it.

Arrow Keys, Almost?????????
i put in this code, and it is a picture1
If KeyCode = 39 Then
' right arrow key was pressed
Picture1.Move Picture1.Left - 100
End If

If KeyCode = 37 Then
' left arrow key was pressed
Picture1.Move Picture1.Left + 100
End If

If KeyCode = 38 Then
' up arrow key was pressed
Picture1.Move Picture1.Top + 100
End If

If KeyCode = 40 Then
' down arrow key was pressed
Picture1.Move Picture1.Top - 100
End If

but it doent move the picture wy? please help

Arrow Keys
what are the VB variables for the arrow keys (up,down,left,right) ?????

Arrow Keys
How do we move across different text boxes in a form using arrows keys- up, down, right and left?

Use Off Arrow-keys
I've got a problem while using the arrow keys to give steering commands to an object(Aircraft). The steering commands do work well, however each time an arrow key is pushed, the focus is also moving along the form and even more painfull, if the focus reaches an option field the selected option will be changed on the way.
Is it possible to "stop" this unwanted sideeffect?

Using Arrow Keys
Hi guys and gals!

I have come across a problem in designing an interface that simply has
me vexed.
The aplication requires keyboard use only (no mouse), so the current
program uses all windows standard accelerators and function keys. A
request has been made to navigate between fields using the arrow keys.
I already have keypreview set to true and am processing keystrokes
through the KeyDown event. However, the arrow keys don't fire any
events at all when pressed by themselves. (I have tried KeyPress as well
to no avail) Although, if I hold down a modifier key (shift, ctrl, alt)
then press the arrow key, the event fires and the code works perfectly.
So it seems to be a bug. I have searched Miscrosoft MSDN and Technet
but can find no information related to this issue.

I know I could hook my window and build my own handler, but I would
prefer to explore all other avenues before resorting to anything that
could potentially cause system instability.

Has anyone experienced this issue and found a solution?

Thank you, Chris

Need Help! Need To Know How To Use Arrow Keys
I already know how to use the letter keys in a form by using the KeyAscii and if..then statements. I made a form changes the event to Form_KeyPress and typed in

label1.caption = KeyAscii

That gave me the Number for most of the keys but it didnt give me one for the arrow keys. Could someone give me sample code on how to use the arrow keys to move an image in a form. Thanks Again ~Greg~

Using The Arrow Keys?
I am working on a simple program to help teach kids their times tables ( 2 x 8 = ). I am using a array of labels to display the math problem. I am trying to use a Shape to indicate which problem is the current one.

The problem I am having is how to use the Arrow keys to move to the next one, or back one problem. How do I use the Arrow keys? I have the logic to do the moving, I just can't get the Arrow keys. I have put my logic (even a Debug.Print ) in the Change event, KeyDown event, KeyPress event and nothing works. In the KeyDown event I get a response but not the right one. Here is what I got so-far:
Code:Private Sub txtAnswer_KeyDown(KeyCode As Integer, Shift As Integer)
    If vbKeyRight Then
    Debug.Print "Right Arrow"
    end if
end sub
this will do the Debug.Print no matter what key I press. Why?

Any Help would be Great

GOD said it, I believe it, so that settles that.....

Edited by - kf4iis on 8/11/2003 11:45:46 AM

Those Pesky Arrow Keys
I'm trying to trap the arrow keys. I have a command button on a frame on a form. I set form.keypreview to true, and try to trap the keydown event on both the form and the button (the frame doesn't have the KeyDown event) but the keypress doesn't show up in either trap. I cant trap lots of other keys, but not the arrows. What's up with that?

Oh, and passel, feel free to tell me how wrong I was when I said that trapping arrow keys was easy (

Trap Arrow Keys
Hi there, All

Is there a way to trap the arrow keys in an MS Access form. I want to be able to scroll through items I have listed in my combobox by pressing the up/left (for previous) and down/right (for next) keys.

I have the keypreview property set to True and placed the code to trap the arrow keys in the Form_KeyDown event. The function works (it does scroll to the next/previous item in the combobox list), but then it loses focus to the next or previous control in the tab order. I've tried to reset focus to the control (combo1.SetFocus) but to no avail.

Any help would be most appriciated.

Arrow Keys To Navigate DB
I have a data project that I want to use the arrow keys, left and right , to go forward and backward in my rs. I want the user to be able to either press my cmdNext or cmdBack , or use the arrow keys. Can someone point me in the right direction to do this?

thank you
Dale S

Form_keydown With Arrow Keys
I'm having a problem triggering the form_keydown event when using the arrow keys. I have the KeyPreview set to true, and It works fine as long as the focus isn't on one of my buttons. However, when one of my buttons are focuses, pressing the arrow key moves to the next button, even though all buttons have TabStop set to false.

Any other way to detect this?

Combo Box And Arrow Keys
here's the question -
I want the user to be able to change the highlighted option in an option box, using the arrow keys on the keyboard. Can this be done? How?

I know that I have to use the arrow keys in the keydown event, but I am not sure how to get the option to change without clicking on the combo box and selecting a different one.

I would like the user to be able to keep pressing the arrow key, and the options in the combo box to cycle through, in order.

Any help appreciated


Intercepting Arrow Keys
I have a form with KeyPress set to true. It has for commandbuttons = Command1(0-3) on it. They are placed in two rows with two columns, i.e.:

Command1(0) Command1(1)
Command1(2) Command1(3)

I want to intercept the arrow keys to set the focus appropriately. For instance, with the focus on Command1(0), I press the down key and the focus should then be on Command1(2). This is the code I use, but it doesn't even seem to be initiated, since the arrow keys work in the default manner (down key moves from 0 to 1). Any suggestions?

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static iC As Integer
Select Case KeyCode
Case vbKeyUp 'Up
iC = iC - 2
If iC < 0 Then iC = iC + 2
Case vbKeyDown 'Down
iC = iC + 2
If iC > 4 Then iC = iC - 2
Case vbKeyRight 'Right
iC = iC + 1
If iC > 4 Then iC = 0
Case vbKeyLeft 'Left
iC = iC - 1
If iC < 0 Then iC = 4
End Select
End Sub

Use Arrow Keys To Navigate
I have a form with about 15 textboxes. At present I am using the TAB and mouse to navigate. The end uesrs are not satisfied. Thay want to use the arrow keys instead.
I have no idea how to tackle this problem. Any help will be appreciated.
Thanks in advance.

How To Use The Arrow Keys In A Form
Hello Guys,

How will I use the arrow keys or the page up or page down keys in a form to navigate thru the texboxes or any object in a form?

Thanks guys!

UserControl Tab And Arrow Keys.
I've used the following code in two custom usercontrols.
It traps the arrow keys and uses PostMessage to call the next control in the tab order.

It works perfectly in the first control I made.
But it isn't working properly in a new control.

Also, the tab key never seems to get to this sub, but it still works with the 1st control.
But with the new control I have to use the tab key twice before focus will shift to the next control.

The original control has the KeyPreview property set to false.
I had to set it to True on the new control, otherwise UserControl_KeyDown never receives the event.

Any ideas?
Maybe I've missed a setting somewhere?

VB Code:
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)'This handles keystrokes made while the button has focus    Static bBlockLoop As Boolean        If bBlockLoop Then Exit Sub    Select Case KeyCode        Case vbKeySpace            bBlockLoop = True            m_eButtonState = Down            SetButtonPic        Case vbKeyReturn            bBlockLoop = True            m_eButtonState = Down            SetButtonPic            UserControl.Refresh            Sleep 50            m_eButtonState = HasFocus            RaiseEvent Click            SetButtonPic        Case vbKeyRight            m_eButtonState = Normal            SetButtonPic            KeyCode = 0             ' simulate a tab key            PostMessage UserControl.ContainerHwnd, WM_KEYDOWN, ByVal &H27, ByVal &H4D0001        Case vbKeyDown            m_eButtonState = Normal            SetButtonPic            KeyCode = 0            PostMessage UserControl.ContainerHwnd, WM_KEYDOWN, ByVal &H28, ByVal &H500001        Case vbKeyLeft            m_eButtonState = Normal            SetButtonPic            KeyCode = 0             ' simulate a shift+tab key            PostMessage UserControl.ContainerHwnd, WM_KEYDOWN, ByVal &H25, ByVal &H4B0001        Case vbKeyUp            m_eButtonState = Normal            SetButtonPic            KeyCode = 0            PostMessage UserControl.ContainerHwnd, WM_KEYDOWN, ByVal &H26, ByVal &H480001    End Select    RaiseEvent KeyDown(KeyCode, Shift)    bBlockLoop = FalseEnd Sub

Pressing The Arrow Keys
How do can I make things happen when I press the arrow keys on my form? Ive been thinking for a while now but I cant figure it out

This is what I thought was the obvious answer:

VB Code:
Private Sub Form_KeyPress(KeyAscii As Integer)    If KeyAscii = vbKeyLeft Then        MsgBox "yehaa!"    End IfEnd Sub

Trapping Arrow Keys
My program should respond to the arrow keys, but I can't trap them individually. Only the KeyDown sub is being called, and they're all 255.


AHH HELP Keypress Arrow Keys
How do i track the pressing of the arrow keys?
They dont fire the keypress event.
Also what is there ascii #?
If they dont have an ascii # can I send an arrow key with sendkeys?

SendKeys && Arrow Keys?
Does anyone have problems sending arrow keys to other applications using SendKeys? Here's my code:

AppActivate "Caption of application here"
SendKeys "{DOWN}"

Arrow Keys, Problem..
Here's my problem. I have a command button (cmdMoveNext) which is used to move through the recordset. I also have data in a datalist box. I coded in my cmdMoveNext_Click so if there was an error, throw up the error and the number. All is well when the user clicks the command button. But if the user uses the up and down arrows on the keyboard to move through the datalist, I get a run time error. I coded in the datalist_KeyPress, to call the cmdMoveNext_click. It's not working. I tried KeyUp, KeyDown, KeyPress, I dont know what else to try?? It just wont trap the errors using the keyboard strokes. Any Comments, thanks

Arrow Keys On The Keyboard
I am using the MSFlexgrid and I am trying to capture the Keycode when the user hits the arrow keys on the keyboard but I notice that when the keys are used it does not fire the KeyPress or the KeyDown Events and I am not sure how to capture those keys. I also tried the LeaveCell() event also but I am not able to capture the event.

Here is a sample of my code:
for some reason it will not capture the keydown code.

Private Sub MSFlexGrid1_LeaveCell()
Dim KeyAscii As Integer

If Not MSFlexGrid1.Text > CStr(0) Then
MSFlexGrid1.Text = ""
End If
MSFlexGrid1 = Format$(MSFlexGrid1, "0.00") 'or whatever format
MSFlexGrid1.CellBackColor = &H80000005 'white
Select Case KeyAscii
Case vbKeyDown
With MSFlexGrid1
mlCellLeft = .CellLeft
mlCellTop = .CellTop
mlCellWidth = .CellWidth
mlCellHeight = .CellHeight
VScroll1.Visible = True
VScroll1.Left = mlCellLeft + 1480
VScroll1.Height = mlCellHeight
VScroll1.Top = mlCellTop + .Top + 20
End With
End Select
End Sub

TreeView And Arrow Keys
I used this code below, possible found here, I can't remember, to put the text from the node in a treeview into a textbox.
How can I do the same if the user uses the arrow keys to navigate the nodes?

I assume it uses the gotfocus.

Code:Dim n As MSComctlLib.Node 'Since other object types may have nodes
Dim strTemp As String

Set n = tv1.HitTest(x, y)

If Not n Is Nothing Then
    Select Case n
        Case "Grading Syllabus", "Junior Syllabus", "Youth Syllabus", "Kyu Grade Syllabus", "Dan Grade Syllabus"
            txtGrade.Text = ""
        Case Else
            strTemp = " Grading Syllabus For " & n.Text & " "
            txtGrade.Width = frmGrading.TextWidth(strTemp) + (6 * (GetSystemMetrics(SM_CXBORDER) * Screen.TwipsPerPixelX))
            txtGrade.Text = strTemp
            txtGrade.Left = tv1.Left
    End Select
End If

Set n = Nothing

Edited by - andy99 on 1/25/2004 6:49:22 AM

I Want To Use Left And Right Arrow Keys

I have a form which has 40 textboxs.I have set taborder of textbox such that focus moves to next textbox.

My operator have the habit of holding notebook in left hand while entering
records,so it is difficult to press tab key to move focus to next box.So it will be easy to use left arrow key or right arrow key to move focus to previous textbox or next textbox.

I want to set setfocus to previous textbox when user presses left arrow key and setfocus to next texbox when user presses right arrow key.

Will anyone help me with code to acheive this functionality.


Arrow Keys Are Not Functioning
The arrowkeys are not functioning when a project with winsock controls are working. I what to know the reason why the arrow keys are not functioning. All other keys other that the arrow keys are functioning properly

How Do I Program My Arrow Keys?
I need to be able to activate my arrow keys from within my program but there doesn’t seem to be a ASCII code for them. Is there another way?

Accessing Arrow Keys

Can Any One Help Me That How I Can Access The Arrow Keys In My Vb Code , So That I Can Perform Different tasks (e.g. Displaying A Message Box) When I Press The Arrow Key.


ComboBox And Arrow Keys
I am using Text Boxes and Combo Boxes in a flexgrid to edit data. I have coded the up and down arrow keys to move the boxes up and down in the grid. When moving the Combo Boxes up and down the arrow key is also setting the text in the combo box. Is there a method or API to disable the combo boxes from displaying text from the list when the up or down arrow key is clicked?

Need KeyAscii For Arrow Keys
I posted earlier regarding using the arrow up key in my application. I think I just have the wrong Asc for the arrow up. Does anyone know what it is.


Focus And Arrow Keys
I have several OptionButtons on a form. In the forms KeyUp event I have a Select Case statement to trigger some code when specific keys are pressed. However when you press any of the arrow keys the focus of the OptionButtons is shifted to the next OptionButton. I don't want the focus to be shifted when pressing the arrow keys I want the necessary code to be executed. The proper code is executed when you press the other keys specified in the Select Case statement. How can I fix this problem? Thanks.

Traping Arrow Keys In MSHFlexgrid
Trying to arrow Key Event in Mshflexgrid.

Used Keydown and Keypress to No avail

What is the Call to do this

Copyright © 2005-08, All rights reserved