Results 1 to 6 of 6

Thread: control mouse position with arrow keys

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    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.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: control mouse position with arrow keys

    Add a Handle on Form.Minimized and Form.Visible and then add :
    "Form1_KeyDown()"
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    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?

  4. #4
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: control mouse position with arrow keys

    Heres an example that handles form visible:
    vb Code:
    1. Private Sub Mouse_Control() Handles Me.VisibleChanged
    2.         If Me.Visible = True Or False Then
    3.             Dim e As System.Windows.Forms.KeyEventArgs
    4.             Dim pos As Point
    5.             Select Case e.KeyCode
    6.                 Case Keys.Left
    7.                     GetCursorPos(pos)
    8.                     SetCursorPos(pos.X - 1, pos.Y)
    9.                 Case Keys.Right
    10.                     GetCursorPos(pos)
    11.                     SetCursorPos(pos.X + 1, pos.Y)
    12.                 Case Keys.Up
    13.                     GetCursorPos(pos)
    14.                     SetCursorPos(pos.X, pos.Y - 1)
    15.                 Case Keys.Down
    16.                     GetCursorPos(pos)
    17.                     SetCursorPos(pos.X, pos.Y + 1)
    18.             End Select
    19.         End If
    20.     End Sub
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    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.

  6. #6
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: control mouse position with arrow keys

    vb Code:
    1. Private Sub Window_State() Handles Me.Resize
    2.         If Not Me.WindowState = FormWindowState.Normal Then
    3.         'Insert code here
    4.         End If
    5. End Sub
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width