Ooops
January 26, 2021, 05:56:05 AM

Author Topic: [bb] Mouse userlib by Eikon [ 1+ years ago ]  (Read 625 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Mouse userlib by Eikon [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Mouse userlib
Author : Eikon
Posted : 1+ years ago

Description : How to automate mouse movement and clicks

Code :
Code: BlitzBasic
  1. ; // [Userlib Entries]
  2. ;.lib "user32.dll"
  3. ;SetCursorPos%(x%, y%)
  4. ;mouse_event%(dwFlags%, dx%, dy%, cButtons%, dwExtraInfo%)
  5.  
  6. ; // B+ Code
  7. ; //=============================
  8. ; // Mouse API Function Example by Eikon
  9. ; //=============================
  10. Desk_W = ClientWidth(Desktop())
  11. Desk_H = ClientHeight(Desktop())
  12.  
  13. ; // [GUI]
  14. Parent = CreateWindow("Automate Mouse", (Desk_W / 2) - 75, (Desk_H / 2) - 50, 150, 100, 0, 1)
  15. New_X  = CreateTextField(5, 5, 64, 18, Parent, 0)
  16. New_Y  = CreateTextField(75, 5, 64, 18, Parent, 0)
  17. Move   = CreateButton ("Move Mouse", 5, 26, 134, 18, Parent, 1)
  18. Simu   = CreateButton ("Simulate Click", 5, 48, 134, 18, Parent, 1)
  19.  
  20. SetGadgetText New_X, Desk_W / 2 ; // [Defaults]
  21. SetGadgetText New_Y, Desk_H / 2
  22.  
  23. ; // [Mouse_Event dwFlag Constants]
  24. Const MOUSEEVENTF_ABSOLUTE   = -32768 ; // Use absolute coords
  25. Const MOUSEEVENTF_MOVE       = 1      ; // Trigger move event
  26. Const MOUSEEVENTF_LEFTDOWN   = 2      ; // LMB Down
  27. Const MOUSEEVENTF_LEFTUP     = 4      ; // LMB Up
  28. Const MOUSEEVENTF_RIGHTDOWN  = 8      ; // RMB Down
  29. Const MOUSEEVENTF_RIGHTUP    = 16     ; // RMB Up
  30. Const MOUSEEVENTF_MIDDLEDOWN = 32     ; // MMB Down
  31. Const MOUSEEVENTF_MIDDLEUP   = 64     ; // MMB Up
  32. Const MOUSEEVENTF_WHEEL      = 128    ; // NT Only: Mouse wheel moved
  33.  
  34. ; // [Main]
  35. Repeat
  36.        
  37. Select WaitEvent()
  38.     Case $803: End
  39.     Case $401 ; // [Gadget Event]
  40.     Select EventSource()
  41.         Case Move ; // [Move Button]
  42.         SetCursorPos Int(TextFieldText(New_X)), Int(TextFieldText(New_Y))                      
  43.         Case Simu  ; // [Simulate Left Click]
  44.         Val% = MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP ; Left Click
  45.         mouse_event Val, 0, 0, 0, 0
  46.        
  47.     End Select
  48. End Select
  49. Forever


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal