I want to write a program that works also if it is minimized. Can anyone help me?
Printable View
I want to write a program that works also if it is minimized. Can anyone help me?
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.
Yeah know that with API but don't know how to use minimezed state that it then also works the keyboard moves
I can't help i'm dutch and 13 years old
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
Thanks, I hope you find the way for the minimized window!
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
Yeah that's the right code Thanks!
I hope I can find the code to push the buttons with right = right ctrl left button = Left Alt
Hee sandertje.. nog een nederlander :)
hehe...
Hey guys, could this be made to work across two machines networked together?
jajah er zijn zoveel nederlanders hierow :)Quote:
Originally posted by Jop
Hee sandertje.. nog een nederlander :)
hehe...
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
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.
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.
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.
[Edited by Matthew Gates on 07-03-2000 at 11:31 PM]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