|
-
Jul 3rd, 2000, 04:22 AM
#1
I want to write a program that works also if it is minimized. Can anyone help me?
-
Jul 3rd, 2000, 04:34 AM
#2
Fanatic Member
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
-
Jul 3rd, 2000, 04:38 AM
#3
Yeah know that with API but don't know how to use minimezed state that it then also works the keyboard moves
-
Jul 3rd, 2000, 04:49 AM
#4
Sorry for me English
I can't help i'm dutch and 13 years old
-
Jul 3rd, 2000, 04:54 AM
#5
Fanatic Member
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
-
Jul 3rd, 2000, 08:39 AM
#6
Thanks, I hope you find the way for the minimized window!
-
Jul 3rd, 2000, 09:11 AM
#7
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
-
Jul 3rd, 2000, 09:26 AM
#8
Yeah that's the right code Thanks!
-
Jul 3rd, 2000, 09:29 AM
#9
I hope I can find the code to push the buttons with right = right ctrl left button = Left Alt
-
Jul 3rd, 2000, 10:12 AM
#10
Frenzied Member
Hee sandertje.. nog een nederlander 
hehe...
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jul 3rd, 2000, 10:40 AM
#11
Fanatic Member
Hey guys, could this be made to work across two machines networked together?
-
Jul 3rd, 2000, 03:11 PM
#12
Junior Member
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 
-
Jul 3rd, 2000, 03:24 PM
#13
Fanatic Member
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
-
Jul 3rd, 2000, 04:47 PM
#14
Fanatic Member
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
-
Jul 3rd, 2000, 05:39 PM
#15
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.
-
Jul 3rd, 2000, 10:28 PM
#16
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|