How can API functions, we simulate mouse events? None of the commands without the PB.
Only api functions.

Code: Select all
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)
Code: Select all
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.
Code: Select all
While GetMessage_(msg.MSG, #Null, 0, 0 )
TranslateMessage_(msg)
DispatchMessage_(msg)
Wend
Code: Select all
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
Code: Select all
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()
Code: Select all
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()