|
-
Apr 8th, 2006, 02:36 AM
#1
Thread Starter
Hyperactive Member
Keyboard + mouse
Hey, I want to make a program so everytime I hit 'q' on my keyboard it left clicks my mouse.. I want it to work exactly as if I hit the mouse button myself.. is this possible?
-
Apr 8th, 2006, 04:32 AM
#2
Addicted Member
Re: Keyboard + mouse
You will need a keyboard hook for that. Following api's might help you to start off :
setwindowshookex
unhookwindowshookex
keyboardproc
The forum has threads on this particular issue. Search for it.
-
Apr 8th, 2006, 06:37 PM
#3
Thread Starter
Hyperactive Member
-
Apr 8th, 2006, 09:36 PM
#4
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
How would I do the mouse click part? i dont want to use
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
cause for some reason they arent working on one application, they work every where else on the screen, but not on that application
-
Apr 8th, 2006, 10:29 PM
#5
Re: Keyboard + mouse
You could use sendkeys to send vbKeyLButton to your application. Or do you want to click the button in some other application?
-
Apr 9th, 2006, 02:53 AM
#6
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
Yes I want to have it click on other applications
-
Apr 9th, 2006, 03:33 AM
#7
Addicted Member
Re: Keyboard + mouse
in a new form with this code you can move mouse with keyboard
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 myPos As POINTAPI
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
GetCursorPos myPos
Select Case KeyCode
Case 37, vbKeyA: myPos.x = myPos.x - 10 'Left key or A
Case 38, vbKeyW: myPos.y = myPos.y - 10 'Top key or W
Case 39, vbKeyD: myPos.x = myPos.x + 10 'Right Key or D
Case 40, vbKeyS: myPos.y = myPos.y + 10 'Down key or S
End Select
SetCursorPos myPos.x, myPos.y
End Sub
for click part i 'm learning and so I don't know....
i hope to explain you....eheh hi!
-
Apr 9th, 2006, 04:44 AM
#8
Addicted Member
-
Apr 9th, 2006, 06:39 AM
#9
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
srisa, that could is useful but it sends the click to a handle, I dont want to do that, I want to just send the click whereever the cursor is
-
Apr 9th, 2006, 06:51 AM
#10
Addicted Member
Re: Keyboard + mouse
In post 6 you said you want to send the click event to another application. If that is the case you have to get a handle to the window of that application and send the message.
-
Apr 9th, 2006, 07:32 AM
#11
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
I want to send the click to a button on the application but none of the buttons have handles, the application only has 1 handle, its written in java or something, so I need to move the cursor there and click the button.. moving the cursor to the button is easy.. clicking it under normal circumstances would be easy, however this application somehow catches virtual mouse clicks and ignores them.. so I need a way simulate a mouse click that tricks the program and makes it think its a real click
-
Apr 9th, 2006, 07:46 AM
#12
Addicted Member
Re: Keyboard + mouse
So , what you want to do is to programatically click a command button in an application. With my limited knowledge , I think that is different from mouse_click event.
-
Apr 9th, 2006, 08:09 AM
#13
Addicted Member
Re: Keyboard + mouse
That being the case, you need to get the handle of the application using findwindow api. After getting the handle of the application window, you can get the handle to the button using findwindowex api, which gets the handle of the child window .(command button is considered to be a child window)
VB Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
tWnd = FindWindow("Shell_TrayWnd", vbNullString)
'Get the start-button's window handle
bWnd = FindWindowEx(tWnd, ByVal 0&, "BUTTON", vbNullString)
this code is from api guide.
After getting handle to the button you can use sendmessage api.
this might be of use.
-
Apr 9th, 2006, 03:27 PM
#14
Re: Keyboard + mouse
 Originally Posted by bail3yz
I want to send the click to a button on the application but none of the buttons have handles, the application only has 1 handle, its written in java or something, so I need to move the cursor there and click the button.
If it's running in Windows, the button has a handle (it's an object that was drawn on the screen).
You have to get the handle of the application whose window is under the cursor, then you have to get the handle of that button in that application, then you send the button a mouse left (or right) click.
You can't just send the application a click unless the application is subclassing all clicks and knows that a click means to execute that button's code - or the application checks the actual location of the cursor relative to itself before processing clicks. Do you do that in your click event? I don't.
-
Apr 9th, 2006, 07:18 PM
#15
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
No, the button does not have to have a handle.. for example a flash application buttons dont have handles, nor does a Java application... which is why I wanted to move the cursor to the location and click..
Something like this
Public Function ClickCoords(X As Long, Y As Long)
SetCursorPos X, Y
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Function
Should work.. it works on every application, including mine and I dont check the location of the cursor before processing clicks..
-
Apr 10th, 2006, 03:49 AM
#16
Addicted Member
Re: Keyboard + mouse
How about this : Set the cursor position and then use sendmessage with
HWND_BROADCAST as the parameter for the window handle. Then all the top_level windows will receive the message.
-
Apr 10th, 2006, 06:56 AM
#17
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
I'll give that a shot, thank you.. Ill let you know if it works
-
Apr 10th, 2006, 07:02 AM
#18
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
nope, no luck there.. once again that method worked on every window except this one application.. i swear they are capturing the simulated mouse clicks somehow and blocking them
-
Apr 10th, 2006, 07:17 AM
#19
Addicted Member
Re: Keyboard + mouse
I am sorry, but I don't know much. Most of what I have posted is done by searching through google. That is one option left. Or if one of the experienced guys around here has a look at your post, they might help you out.
-
Apr 10th, 2006, 07:19 AM
#20
Addicted Member
Re: Keyboard + mouse
this link uses sendinput. See if that helps.
-
Apr 10th, 2006, 08:25 PM
#21
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
ya I tried that too lol no luck , thanks for all the help tho srisa
-
Apr 10th, 2006, 08:50 PM
#22
Lively Member
Re: Keyboard + mouse
use AutoIT
and heres the code (should work)
When you use this you wont be able to use your mouse till you pause the script with w
VB Code:
HotKeySet("q","Click")
HotKeySet("w","Waiting")
Call("Waiting")
Func Waiting()
while 1 = 1
sleep(1000)
wend
EndFunc
Func Click()
$Pos = MouseGetPos()
while 1 = 1
MouseClick("left",$Pos[0], $Pos[1], 1, 0)
wend
EndFunc
Last edited by BladeZ; Apr 10th, 2006 at 08:53 PM.
-
Apr 11th, 2006, 02:20 AM
#23
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
i will give that a shot, but if autoit could do it, shouldnt there be away to code it into a VB app?
-
Apr 11th, 2006, 02:55 AM
#24
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
that actually worked Bladez wish I knew how to do that in VB without 3rd party software..
-
Apr 11th, 2006, 03:06 AM
#25
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
i see autoit has a DLL version, is there anyway to load that into vb and get it to work via my VB app?
-
Apr 11th, 2006, 02:02 PM
#26
Lively Member
Re: Keyboard + mouse
Heres a thread i found that has a example of how to do it
Thread
-
Apr 12th, 2006, 02:49 AM
#27
Thread Starter
Hyperactive Member
Re: Keyboard + mouse
dude, you are my hero ty so much
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
|