to sparkie or winapi gurus- mouse events and winapi-

Just starting out? Need help? Post your questions and find answers here.
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

to sparkie or winapi gurus- mouse events and winapi-

Post 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
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

you can try Droopy lib Mouse & Keyboard functions ?
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

Post 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
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Help / External Help / Droopy Lib
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

Post 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
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

sorry i read your post too fast :oops:
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

Post 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
Post Reply