It is currently Fri Jan 19, 2018 2:50 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: simulate mouse events?
PostPosted: Fri Jan 14, 2011 6:58 am 
Offline
User
User

Joined: Sun Dec 19, 2010 7:46 pm
Posts: 40
Location: ovanaro
Hi All,
How can API functions, we simulate mouse events? None of the commands without the PB.
Only api functions. :shock:


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Fri Jan 14, 2011 10:38 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Dec 30, 2007 7:24 pm
Posts: 104
What sort of events do you wish to simulate and in what context?


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Fri Jan 14, 2011 10:40 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 18, 2010 4:40 am
Posts: 151
I don't know if you want to use API commands or not... but here:

Code:
GetCursorPos_(mouse.POINT)
Debug mouse\x
Debug mouse\y

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)

mouse_event_(#MOUSEEVENTF_MIDDLEDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_MIDDLEUP,0,0,0,0)


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Fri Jan 14, 2011 11:41 am 
Offline
User
User

Joined: Sun Dec 19, 2010 7:46 pm
Posts: 40
Location: ovanaro
For example, if I want to do the following program defining event, what to write?

Code:
OpenWindow(0,0,0,800,600,"My",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

;For example, the closing event for the window.  (only Api Function)

or

ButtonGadget(33,450,140,60,90,"")

;Event for double-click on the button. (only Api Function)
;Ie when we double-click on the button , display message.


How are the objects in Pb by API event be defined? I need these functions. :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Sat Jan 15, 2011 12:54 pm 
Offline
User
User

Joined: Sun Dec 19, 2010 7:46 pm
Posts: 40
Location: ovanaro
Who knows how the function WaitWindowEvent() have produced?
Whether these codes have been used?

Code:
  While GetMessage_(msg.MSG, #Null, 0, 0 )
  TranslateMessage_(msg)
  DispatchMessage_(msg)
  Wend


Please if you have information provided in this regard let me.


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Sat Jan 15, 2011 1:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 18, 2010 4:40 am
Posts: 151
What are you trying to do? Learn how PureBasic converts it native commands to API?


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Sat Jan 15, 2011 1:46 pm 
Offline
User
User

Joined: Sun Dec 19, 2010 7:46 pm
Posts: 40
Location: ovanaro
I love to learn how the Pb, the job is done. :D
I asked the question whether hard? :shock:
Ie one can not give answers to these questions? :?


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Sat Jan 15, 2011 10:52 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Aug 16, 2010 4:29 am
Posts: 252
You can override the normal event data like this: (I only show the ClickType portion of the override here. You will also need sim override data for PBEventGadget, EventGadget, whatever your app uses.)
Code:
SimEvent = #PB_EventType_LeftDoubleClick
Gosub MouseEvent
;
;
;
MouseEvent:
If Simevent <> 0
  Event = Simevent
Else
  Event = WaitWindowEvent()
EndIf
       
       Select Event
       
         Case #PB_Event_Gadget
           Select EventGadget()
             Case 1
               Select EventType()
                 Case #PB_EventType_LeftClick        : Debug "Click with left mouse button"
                 Case #PB_EventType_RightClick       : Debug "Click with right mouse button"
                 Case #PB_EventType_LeftDoubleClick  : Debug "Double-click with left mouse button"
                 Case #PB_EventType_RightDoubleClick : Debug "Double-click with right mouse button"
               EndSelect
           EndSelect
       
       EndSelect
Simevent = 0
Return


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Sun Dec 10, 2017 5:41 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2184
I am trying to send mouse events to an external windows program, not sure if it can be done "seemless" - without moving the mouse around and no matter if the window is in the background (and overlapped by other windows), etc.

Here's a sample code, I'd like to push button "1" and "2" of the left window by activating them by the right window. Button 2 works but with a lot of restrictions. The method for button 1 fails completely.

Are there any chances for improvements?

Code:

Macro MakeLong(low,high)
   (((high&$FFFF)<<16) | (low&$FFFF))
EndMacro

Procedure Main()

   Protected x,y
   Protected point.Point
   Protected cursor.Point
   Protected IqHandle

   IqHandle=OpenWindow(0,100,100,200,200,"")

   ButtonGadget(1,20,20,40,20,"1")
   ButtonGadget(2,20,50,40,20,"2")

   OpenWindow(1,400,100,200,200,"Control")
   ButtonGadget(666,20,20,40,20,"Go 1")
   ButtonGadget(999,20,40,40,20,"Go 2")

   Repeat

      Select WaitWindowEvent()

      Case #PB_Event_Gadget
         Select EventGadget()
         Case 666
            PostMessage_(IqHandle,#WM_LBUTTONDOWN,0, MakeLong(25,25))
            PostMessage_(IqHandle,#WM_LBUTTONUP,0, MakeLong(25,25))

         Case 999
            If IsWindowVisible_(IqHandle)
               point\x=25
               point\y=50
               ClientToScreen_(IqHandle,point)

               GetCursorPos_(cursor)
               SetCursorPos_(point\x,point\y)
               mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
               mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
               SetCursorPos_(cursor\x,cursor\y)
            EndIf

         Case 1
            MessageRequester("","1")
         Case 2
            MessageRequester("","2")
         EndSelect

      Case #PB_Event_CloseWindow
         End

      EndSelect

   ForEver

EndProcedure

Main()


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Sun Dec 10, 2017 7:15 pm 
Offline
User
User

Joined: Mon Mar 17, 2014 1:42 pm
Posts: 91
Hi
I don't know if i understood correctly :wink:
Code:
Global A,B$,IqHandle,BUTTON1,BUTTON2
Macro MakeLong(low,high)
   (((high&$FFFF)<<16) | (low&$FFFF))
EndMacro

Procedure EnumChildProc(hwnd, lParam)

 
  VALUE=AllocateMemory(128)
  ; For any hwnd, you can 'nest' calls to EnumChildWindows and to other EnumChildProc
  result = #True ; continue searching
  If GetWindowText_(hwnd, VALUE, 128)
    If PeekS(VALUE)=B$
      A=hwnd
      result = #False ; search succesful, stop callback, do whatever
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

Procedure gethandle()
  Shared statusbar
  ;automatically get the handle 2 buttons
  HANDLE=IqHandle
  If HANDLE
    GetWindowThreadProcessId_(HANDLE, @ProcID_)
    Global hProc_ = OpenProcess_(#PROCESS_ALL_ACCESS, 0, ProcID_)
    B$="1"
    EnumChildWindows_(HANDLE, @EnumChildProc(), 0)
    BUTTON1=A
    B$="2"
    EnumChildWindows_(HANDLE, @EnumChildProc(), 0)
    BUTTON2=A
  EndIf
EndProcedure




Procedure Main()

   Protected x,y
   Protected point.Point
   Protected cursor.Point
   ;Protected IqHandle

   IqHandle=OpenWindow(0,100,100,200,200,"")

   ButtonGadget(1,20,20,40,20,"1")
   ButtonGadget(2,20,50,40,20,"2")

   OpenWindow(1,400,100,200,200,"Control")
   ButtonGadget(666,20,20,40,20,"Go 1")
   ButtonGadget(999,20,40,40,20,"Go 2")
   gethandle()
   Repeat

      Select WaitWindowEvent()

      Case #PB_Event_Gadget
         Select EventGadget()
         Case 666
            SendMessage_(BUTTON1,#WM_LBUTTONDOWN,0,0)
            SendMessage_(BUTTON1,#WM_LBUTTONUP,0,0)
           
            SendMessage_(BUTTON2,#WM_LBUTTONDOWN,0,0)
            SendMessage_(BUTTON2,#WM_LBUTTONUP,0,0)

         Case 999
            If IsWindowVisible_(IqHandle)
               point\x=25
               point\y=50
               ClientToScreen_(IqHandle,point)

               GetCursorPos_(cursor)
               SetCursorPos_(point\x,point\y)
               mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
               mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
               SetCursorPos_(cursor\x,cursor\y)
            EndIf

         Case 1
            MessageRequester("","1")
         Case 2
            MessageRequester("","2")
         EndSelect

      Case #PB_Event_CloseWindow
         End

      EndSelect

   ForEver

EndProcedure


Main()

_________________
simpleZX


Top
 Profile  
Reply with quote  
 Post subject: Re: simulate mouse events?
PostPosted: Mon Dec 11, 2017 1:36 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2184
Thanks Otrebor, but the problem for me is, that the target program (Garmin IQ Simulator) does not have specific buttons but only a bitmap where a mouseclick on different areas do some actions (so my example was not the best to explain what should be done :oops: ).
Id' like to control this software by keyboard shortcuts instead of moving around with the mouse. Not sure if there would be another aprroach than the one seen above...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye