Results 1 to 16 of 16

Thread: Want to move mouse with my keyboard

  1. #1
    Guest

    Question

    I want to write a program that works also if it is minimized. Can anyone help me?

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    Thumbs up Sander! Are you still awake?

    You use a key press event with the API SetCursorPos. If you don't know, I will whip up a batch of code for you right now.
    Chemically Formulated As:
    Dr. Nitro

  3. #3
    Guest
    Yeah know that with API but don't know how to use minimezed state that it then also works the keyboard moves

  4. #4
    Guest

    Sorry for me English

    I can't help i'm dutch and 13 years old

  5. #5
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    I am not sure about the minimize part but here is the codes to moving the cursor. I will try to think of a way to move the cursor while the form is minimize.

    Code:
    Option Explicit
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Dim r_Positon As POINTAPI
      Call GetCursorPos(r_Positon)
      
      Select Case KeyCode
          Case vbKeyRight
            Call SetCursorPos(r_Positon.X + 5, r_Positon.Y)
          Case vbKeyLeft
            Call SetCursorPos(r_Positon.X - 5, r_Positon.Y)
          Case vbKeyDown
            Call SetCursorPos(r_Positon.X, r_Positon.Y + 5)
          Case vbKeyUp
            Call SetCursorPos(r_Positon.X, r_Positon.Y - 5)
      End Select
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  6. #6
    Guest
    Thanks, I hope you find the way for the minimized window!

  7. #7
    Guest
    Use the GetAsyncKeyState API. Make a Timer, Set its Interval to 1 and place the following code in your Form. You modify Amount to how much you want the cursor to move each time.

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Dim CurPos As POINTAPI
    Dim Amount As Integer
    
    
    Private Sub Timer1_Timer()
    
        Amount = 10
        RetVal = GetCursorPos(CurPos)
    
        If GetAsyncKeyState(vbKeyLeft) Then SetCursorPos CurPos.X - Amount, CurPos.Y
        If GetAsyncKeyState(vbKeyRight) Then SetCursorPos CurPos.X + Amount, CurPos.Y
        If GetAsyncKeyState(vbKeyUp) Then SetCursorPos CurPos.X, CurPos.Y - Amount
        If GetAsyncKeyState(vbKeyDown) Then SetCursorPos CurPos.X, CurPos.Y + Amount
        
    End Sub

  8. #8
    Guest
    Yeah that's the right code Thanks!

  9. #9
    Guest
    I hope I can find the code to push the buttons with right = right ctrl left button = Left Alt

  10. #10
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Hee sandertje.. nog een nederlander
    hehe...
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  11. #11
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550
    Hey guys, could this be made to work across two machines networked together?

  12. #12
    Junior Member
    Join Date
    Apr 2000
    Posts
    27

    Holland 4 Ever! ;)

    Originally posted by Jop
    Hee sandertje.. nog een nederlander
    hehe...
    jajah er zijn zoveel nederlanders hierow
    Life's hard, but the front of a train is harder

  13. #13
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Megatron!

    I have never use GetAsyncKeyState before. Very impressive. How would you put your code in a Case Select style instead of If statments? I am not really sure what that API returns.

    Thanks
    Chemically Formulated As:
    Dr. Nitro

  14. #14
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Another thing, GetAsynkeyState, what does it return? Does it just check what is in the buffer? If that is the case, what API can I use to check what is in the buffer without applying a key such as VBKEYRight.
    Chemically Formulated As:
    Dr. Nitro

  15. #15
    Guest
    It will return a 1 if the Function is successful (the key is pressed) and a 0 if the Function fails.

    You can use a Select Case style but you'll end up having to do more in the long run, so it's fine in the If...Then style.

  16. #16
    Guest

    Speaking of moving mouse...

    This code is good for gaming. Has nothing to do with moving the mouse..but I thought it might be useful for those who don't know. Move a picture/image/label, anything up, down, left, or right.
    Code:
    If keycode = 39 Then
    'right key
    Picture1.Move Picture1.Left + 100
    End If
    If keycode = 37 Then
    'left key
    Picture1.Move Picture1.Left - 100
    End If
    If keycode = 38 Then
    'up key
    Picture1.Move Picture1.Top + 100
    End If
    If keycode = 40 Then
    'down key
    Picture1.Move Picture1.Top - 100
    End If
    [Edited by Matthew Gates on 07-03-2000 at 11:31 PM]

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