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
to sparkie or winapi gurus- mouse events and winapi-
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
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
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
Hi Mike. 
I'm not exactly sure what your needs are here, but is this close to what you're looking for?

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
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
- User
- Posts: 22
- Joined: Sun Feb 15, 2004 5:34 pm
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!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
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