-
Jul 20th, 2008, 11:47 AM
#1
Thread Starter
Hyperactive Member
control mouse position with arrow keys
well i can control the position of the mouse while the form has focus. But that is now what i want. i want to be able to control the mouse while the form is minimized or hidden or in the system tray. this is my working move mouse code maybe it could be optimized but i think it is good.
Code:
Public Class Form1
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim pos As Point
Select Case e.KeyCode
Case Keys.Left
GetCursorPos(pos)
SetCursorPos(pos.X - 1, pos.Y)
Case Keys.Right
GetCursorPos(pos)
SetCursorPos(pos.X + 1, pos.Y)
Case Keys.Up
GetCursorPos(pos)
SetCursorPos(pos.X, pos.Y - 1)
Case Keys.Down
GetCursorPos(pos)
SetCursorPos(pos.X, pos.Y + 1)
End Select
End Sub
Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer
Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As Point) As Long
End Class
thank you for any help you may offer.
-
Jul 20th, 2008, 11:53 AM
#2
Hyperactive Member
Re: control mouse position with arrow keys
Add a Handle on Form.Minimized and Form.Visible and then add :
"Form1_KeyDown()"
-
Jul 20th, 2008, 11:58 AM
#3
Thread Starter
Hyperactive Member
Re: control mouse position with arrow keys
i dont understand what you mean. i dont know where to add a handler can you make it clearer or provide code?
-
Jul 20th, 2008, 12:04 PM
#4
Hyperactive Member
Re: control mouse position with arrow keys
Heres an example that handles form visible:
vb Code:
Private Sub Mouse_Control() Handles Me.VisibleChanged If Me.Visible = True Or False Then Dim e As System.Windows.Forms.KeyEventArgs Dim pos As Point Select Case e.KeyCode Case Keys.Left GetCursorPos(pos) SetCursorPos(pos.X - 1, pos.Y) Case Keys.Right GetCursorPos(pos) SetCursorPos(pos.X + 1, pos.Y) Case Keys.Up GetCursorPos(pos) SetCursorPos(pos.X, pos.Y - 1) Case Keys.Down GetCursorPos(pos) SetCursorPos(pos.X, pos.Y + 1) End Select End If End Sub
-
Jul 20th, 2008, 12:18 PM
#5
Thread Starter
Hyperactive Member
Re: control mouse position with arrow keys
it would need to handle something other than me.visiblechanged because that is only called when the visible state is being changed not when it isn't visible. so further help is needed.
-
Jul 20th, 2008, 12:29 PM
#6
Hyperactive Member
Re: control mouse position with arrow keys
vb Code:
Private Sub Window_State() Handles Me.Resize If Not Me.WindowState = FormWindowState.Normal Then 'Insert code here End If End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|