Simulating a mouseclick?

Reply

Join Date: May 2008
Posts: 42
Reputation: tondeuse34 is an unknown quantity at this point 
Solved Threads: 2
tondeuse34's Avatar
tondeuse34 tondeuse34 is offline Offline
Light Poster

Simulating a mouseclick?

 
0
  #1
May 10th, 2008
Hey guys, is it possible to simulate a mouse click using x and y co-ordinates. And also could you have user input of a certain co-ordinate and it would click that specified co-ordinate? thanks.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 39
Reputation: Shadow14l is an unknown quantity at this point 
Solved Threads: 7
Shadow14l Shadow14l is offline Offline
Light Poster

Re: Simulating a mouseclick?

 
0
  #2
May 12th, 2008
I found a very neat sample of doing this:

  1. from ctypes import *
  2. import time, curses, win32con, win32gui
  3.  
  4. PUL = POINTER(c_ulong)
  5.  
  6. class KeyBdInput(Structure):
  7. _fields_ = [("wVk", c_ushort),
  8. ("wScan", c_ushort),
  9. ("dwFlags", c_ulong),
  10. ("time", c_ulong),
  11. ("dwExtraInfo", PUL)]
  12.  
  13. class HardwareInput(Structure):
  14. _fields_ = [("uMsg", c_ulong),
  15. ("wParamL", c_short),
  16. ("wParamH", c_ushort)]
  17.  
  18. class MouseInput(Structure):
  19. _fields_ = [("dx", c_long),
  20. ("dy", c_long),
  21. ("mouseData", c_ulong),
  22. ("dwFlags", c_ulong),
  23. ("time",c_ulong),
  24. ("dwExtraInfo", PUL)]
  25.  
  26. class Input_I(Union):
  27. _fields_ = [("ki", KeyBdInput),
  28. ("mi", MouseInput),
  29. ("hi", HardwareInput)]
  30.  
  31. class Input(Structure):
  32. _fields_ = [("type", c_ulong),
  33. ("ii", Input_I)]
  34.  
  35. class POINT(Structure):
  36. _fields_ = [("x", c_ulong),
  37. ("y", c_ulong)]
  38.  
  39. def click(x,y):
  40.  
  41. orig = POINT()
  42.  
  43. windll.user32.GetCursorPos(byref(orig))
  44.  
  45. windll.user32.SetCursorPos(x,y)
  46.  
  47. FInputs = Input * 2
  48. extra = c_ulong(0)
  49.  
  50. ii_ = Input_I()
  51. ii_.mi = MouseInput( 0, 0, 0, 2, 0, pointer(extra) )
  52.  
  53. ii2_ = Input_I()
  54. ii2_.mi = MouseInput( 0, 0, 0, 4, 0, pointer(extra) )
  55.  
  56. x = FInputs( ( 0, ii_ ), ( 0, ii2_ ) )
  57.  
  58. windll.user32.SendInput(2, pointer(x), sizeof(x[0]))
  59.  
  60. return orig.x, orig.y
  61.  
  62.  
  63. click(150, 150)

It may be long, but it is one of the few examples I have seen that work with little hassle in Python.

For your second question, I'd probably bind with gui. Follow the example here but it doesn't have to be right click:

http://www.daniweb.com/forums/post598858.html
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 42
Reputation: tondeuse34 is an unknown quantity at this point 
Solved Threads: 2
tondeuse34's Avatar
tondeuse34 tondeuse34 is offline Offline
Light Poster

Re: Simulating a mouseclick?

 
0
  #3
May 13th, 2008
also, how would you use Tkinter with two buttons for example to save a .txt document all you have to do is click that button and it will make a prompt for the filename and save it. Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 149
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Simulating a mouseclick?

 
0
  #4
May 13th, 2008
If you're talking about mouse clicks in Tkinter, then you will want to check out the manual:

http://infohost.nmt.edu/tcc/help/pub...er/tkinter.pdf

OR in HTML format

http://infohost.nmt.edu/tcc/help/pubs/tkinter/
http://www.pythonware.com/library/index.htm

To get mouse clicks, check out the Bind method at the end of the manual. To handle file dialogs, check out the tkFileDialog module.

Hope that helps,
Jeff
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 42
Reputation: tondeuse34 is an unknown quantity at this point 
Solved Threads: 2
tondeuse34's Avatar
tondeuse34 tondeuse34 is offline Offline
Light Poster

Re: Simulating a mouseclick?

 
0
  #5
May 13th, 2008
thanks answered my question
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC