Page 1 of 1
to sparkie or winapi gurus- mouse events and winapi-
Posted: Tue Nov 01, 2005 8:27 pm
by mikecaliber
is there a winapi command that i can use to send to a window mouse commands?
let's say that there is a program called "test" that is running (not a program that i created).
what i want to do is when i press the left mouse button (no matter when or what window or program has the focus) then the program "test" will be sent commands that simulate the movement of a mouse in whatever directions i choose (for instance down 3 pixels and over 10 pixels or something similar). it will be like i keep moving the mouse down and over in the program "test" as long as the left mouse button is pressed down.
i am capturing the left mouse button down using
If GetAsyncKeyState_(#VK_LBUTTON)<>0
is this the best way to capture the button down (fastest and also doesn't matter which window has the focus, etc.)
thanks in advance!
cal
Posted: Tue Nov 01, 2005 9:28 pm
by Droopy
you can try Droopy lib Mouse & Keyboard functions ?
Posted: Tue Nov 01, 2005 9:34 pm
by mikecaliber
thanks droopy, and i will look at that. but i still want more replies and ideas. bump for more views and responses-
btw, how do you USE your library? no apparent help file or anything-
best,
mike
Posted: Tue Nov 01, 2005 10:06 pm
by Droopy
Help / External Help / Droopy Lib
Posted: Tue Nov 01, 2005 10:40 pm
by mikecaliber
droopy,
i don't see how i can simulate what i asked with your library. (nice library, btw!)
what i want is to simulate that i am moving the mouse to a certain degree. i have been trying to come up with an example of how i need this to work. for instance, imagine playing a shooter type game where you move the mouse and the screen rotates based upon your left or right mouse movements. you aren't trying to move a cursor, you are trying to simulate moving the mouse (mouse events). does your library have a way to simulate this? i don't want to place the mouse cursor at location x, y- i want to make it seem to the other program that i am moving the mouse down and right or whatever to a certain degree. does this make sense?
thanks for linking to your library. i might find other items there for later!
best,
mike
Posted: Tue Nov 01, 2005 10:54 pm
by Droopy
sorry i read your post too fast

Posted: Wed Nov 02, 2005 6:02 am
by Sparkie
Hi Mike.
I'm not exactly sure what your needs are here, but is this close to what you're looking for?
Code: Select all
If OpenWindow(0, 0, 0, 200, 200, #PB_Window_SystemMenu, "Test") And CreateGadgetList(WindowID(0))
RunProgram("Notepad.exe")
Delay(500)
hNotepad = FindWindow_("Notepad", "Untitled - Notepad")
SetWindowPos_(hNotepad, 0, 210, 0, 500, 500, 0)
TextGadget(0, 10, 10, 180, 80, "Hold down on the left mouse button in this window while moving the mouse.")
Repeat
event = WaitWindowEvent()
Select event
Case #WM_LBUTTONDOWN
SetWindowPos_(hNotepad, 0, DesktopMouseX() + 200, DesktopMouseY() - 28, -1, -1, #SWP_NOSIZE | #SWP_NOACTIVATE)
Case #WM_MOUSEMOVE
If GetAsyncKeyState_(#VK_LBUTTON)
SetWindowPos_(hNotepad, 0, DesktopMouseX() + 200, DesktopMouseY() - 28, -1, -1, #SWP_NOSIZE | #SWP_NOACTIVATE)
EndIf
EndSelect
Until event = #PB_EventCloseWindow
EndIf
End
Posted: Tue Nov 08, 2005 5:28 pm
by mikecaliber
Sparkie wrote:Hi Mike.
I'm not exactly sure what your needs are here, but is this close to what you're looking for?
Code: Select all
If OpenWindow(0, 0, 0, 200, 200, #PB_Window_SystemMenu, "Test") And CreateGadgetList(WindowID(0))
RunProgram("Notepad.exe")
Delay(500)
hNotepad = FindWindow_("Notepad", "Untitled - Notepad")
SetWindowPos_(hNotepad, 0, 210, 0, 500, 500, 0)
TextGadget(0, 10, 10, 180, 80, "Hold down on the left mouse button in this window while moving the mouse.")
Repeat
event = WaitWindowEvent()
Select event
Case #WM_LBUTTONDOWN
SetWindowPos_(hNotepad, 0, DesktopMouseX() + 200, DesktopMouseY() - 28, -1, -1, #SWP_NOSIZE | #SWP_NOACTIVATE)
Case #WM_MOUSEMOVE
If GetAsyncKeyState_(#VK_LBUTTON)
SetWindowPos_(hNotepad, 0, DesktopMouseX() + 200, DesktopMouseY() - 28, -1, -1, #SWP_NOSIZE | #SWP_NOACTIVATE)
EndIf
EndSelect
Until event = #PB_EventCloseWindow
EndIf
End
Thanks for the reply Sparkie. I finally figured it out (had to look up these obscure mouse_event structs, etc.) but it works no matter which window has the focus, etc. give it a try!
here's the code:
Repeat
If GetAsyncKeyState_(#VK_LBUTTON)<>0
sleeptime = 10
mouse_event_(#MOUSEEVENTF_MOVE, 1,1, 0, 0 )
sleep_(sleeptime)
EndIf
ForEver
the numbers 1 within the mouse_event control the amount to move and the sleeptime allows a certain pause before it moves again-
thanks for the responses here and thanks for all your help in the forums Sparkie!
best,
cal