December 04, 2020, 11:07:42 AM

Author Topic: [bmx] Programmatically click the mouse by Who was John Galt? [ 1+ years ago ]  (Read 575 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Programmatically click the mouse
Author : Who was John Galt?
Posted : 1+ years ago

Description : Windows only at the mo. Button_down simulates a button down event, and button_up and mouse button release event. Values for button are as per mousedown() function. Additions/improvements welcomed.

Code :
Code: BlitzMax
  1. Global GetLastError:Int() "win32"
  2. Global SendInput(nInputs,pInputs,cbSize) "win32"
  3.  
  4. kernel32 = LoadLibraryA ("kernel32.dll")
  5. If kernel32
  6.         GetLastError=GetProcAddress(kernel32, "GetLastError")
  7. Else
  8.    Print "Kernel32 dead"; End
  9. EndIf
  10.  
  11. user32 = LoadLibraryA ("user32.dll")
  12. If user32
  13.         SendInput=GetProcAddress(user32, "SendInput")
  14. Else
  15.    Print "User32 dead"; End
  16. EndIf
  17.  
  18. Rem
  19. UINT SendInput(          UINT nInputs,
  20.     LPINPUT pInputs,
  21.     Int cbSize
  22. );
  23. EndRem
  24.  
  25. Type Tbuf_input
  26.         Rem
  27.                         typedef struct tagINPUT {
  28.           DWORD Type;
  29.           union {MOUSEINPUT mi;
  30.                     KEYBDINPUT ki;
  31.                     HARDWAREINPUT hi;
  32.                    };
  33.           }Input, *PINPUT;
  34.        
  35.        
  36.                 typedef struct tagMOUSEINPUT {
  37.                 LONG dx;
  38.                 LONG dy;
  39.                 DWORD mouseData;
  40.                 DWORD dwFlags;
  41.                 DWORD time;
  42.                 ULONG_PTR dwExtraInfo;
  43.                 } MOUSEINPUT, *PMOUSEINPUT;
  44.        
  45.                
  46.         EndRem
  47.        
  48.         Rem
  49.         #define MOUSEEVENTF_MOVE        0x0001 /* mouse move */
  50.         #define MOUSEEVENTF_LEFTDOWN    0x0002 /* Left button down */
  51.         #define MOUSEEVENTF_LEFTUP      0x0004 /* Left button up */
  52.         #define MOUSEEVENTF_RIGHTDOWN   0x0008 /* Right button down */
  53.         #define MOUSEEVENTF_RIGHTUP     0x0010 /* Right button up */
  54.         #define MOUSEEVENTF_MIDDLEDOWN  0x0020 /* middle button down */
  55.         #define MOUSEEVENTF_MIDDLEUP    0x0040 /* middle button up */
  56.         #define MOUSEEVENTF_XDOWN       0x0080 /* x button down */
  57.         #define MOUSEEVENTF_XUP         0x0100 /* x button down */
  58.         #define MOUSEEVENTF_WHEEL       0x0800 /* wheel button rolled */
  59.         #define MOUSEEVENTF_VIRTUALDESK 0x4000 /* map To entire virtual Desktop */
  60.         #define MOUSEEVENTF_ABSOLUTE    0x8000 /* absolute move */
  61.         EndRem
  62.        
  63.        
  64.        
  65.         Field _type=0          
  66.         'mouse bits
  67.         Field dx:Int=0         
  68.         Field dy:Int=0
  69.         Field mousedata=0       'int or dword=16 bits
  70.         Field dwFlags=0
  71.         Field time=0
  72.         Field dwExtraInfo:Long Ptr=Null
  73.        
  74.         Method input_ptr()
  75.                 Return Int(Varptr(_type))
  76.         End Method
  77. End Type
  78.  
  79. Type Tmouse_controller
  80.         Global buffer_input:Tbuf_input=New Tbuf_input
  81.         Global down_events[]=[$2,$8,$20]
  82.         Global up_events[]=[$4,$10,$40]
  83.         Global input_pointer=buffer_input.input_ptr()
  84.        
  85.         Method button_down(button)
  86.                 buffer_input.dwFlags=down_events[button-1]
  87.                 sendinput(1,input_pointer,28)
  88.         End Method
  89.        
  90.         Method button_up(button)
  91.                 buffer_input.dwFlags=up_events[button-1]
  92.                 sendinput(1,input_pointer,28)
  93.         End Method
  94. End Type
  95.  
  96. Graphics 800,600,0
  97. Global mousecont:Tmouse_controller=New Tmouse_controller
  98.  
  99. Repeat
  100.         Cls
  101.        
  102.         mousecont.button_down(3)
  103.        
  104.         'e=GetLastError()
  105.         'DrawText e,100,500
  106.         If MouseDown(1) DrawText "Button 1 down",100,100
  107.         If MouseDown(2) DrawText "Button 2 down",100,200
  108.         If MouseDown(3) DrawText "Button 3 down",100,300
  109.                
  110.         Flip()
  111.        
  112. Until KeyHit(KEY_ESCAPE)


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal