Performing a mouse click using python

Is it possible?
I tried to use this script but it doesn't work:
#!/usr/bin/python
import Tkinter as tk
def change_color(event):
btn1.config(fg='red')
root = tk.Tk()
btn1 = tk.Button(root, text='Click me with the right mouse button ...')
btn1.pack()
btn1.bind('<Button-1>', change_color)
root.mainloop()
Thanks.

Yes, I would like to do it without deps.
Here:
#!/usr/bin/env python
from Xlib.display import Display
from Xlib import X
from Xlib.protocol import event
import time
display = Display()
focus = display.get_input_focus().focus
keycode = 1
state = 0
keyevt = event.KeyPress(
detail=keycode,
time=X.CurrentTime,
root=display.screen().root,
window=focus,
child=X.NONE,
root_x=1,
root_y=1,
event_x=1,
event_y=1,
state=state,
same_screen=1)
state=1
keyevt2 = event.KeyPress(
detail=keycode,
time=X.CurrentTime,
root=display.screen().root,
window=focus,
child=X.NONE,
root_x=1,
root_y=1,
event_x=1,
event_y=1,
state=state,
same_screen=1)
focus.send_event(keyevt)
focus.send_event(keyevt2)
I think the problem is with the "state".
I checked it with xev, and it tells that the state on press is 0x10 (16 decimal?) and on release is 0x110 (272 decimal?).
I tried using these values too, and again, not working.
In addition, X.CurrentTime returns 0, so I tried using int(time.time()), and still, not working.
Any suggestions?
Thanks

Similar Messages

  • Simulate Mouse Click using AppleScript

    I want to simulate a mouse click using AppleScript. I used click button of window command but unfortunately it only simulates a half click in the sense that you see the button highlighted but the action is not activated. I used a command key function, where I would press a # many times to make the mouse go down. However, this is very slow. I noticed that there is a couple of additional elements that can be used with AppleScript for example XTools and Extra Suites where I can tell the mouse to go to a certain location and click. I am on a Mac OS X 10.3.9 system (I believe I am using a PowerMac as well) and would like to know if any of the two programs are compatible with this system. I would appreciate any help in how I can install the software and what directory to place the software. Thank you very much for your help.

    Hi, I don't know if the latest version works in 10.3, but might try Quickeys...
    http://startly.com/products/quickeys/mac/4/
    Extra Suites should tell you if it works or not when installing.
    For old Mac SW...
    http://www.oldapps.com/mac/?ModPagespeed=noscript
    I think the most modern Browser for Panther/10.3.9 is Camino...
    http://caminobrowser.org/releases/1.6.9/
    Or iCab 4.8...
    http://www.icab.de/dl.php

  • Perform mouse clicks outside application

    Does anyone now hot you would tell the computer to perform a mouse click, but not on the main application? i.e. You can set the mouse cursor position easily, but can you tell the mouse to click on say an icon that is on the desktop, if the mouse cursor is over it???
    I think JNI will be involved but I don not now.
    Any hints will be a great help.
    US101

    Have you had a look at java.awt.Robot (Introduced in Java 1.3)?

  • Macbook Pro crashes on mouse click

    Hello everyone,
    I've been having this problem for two weeks now and it's happening more and more frequently!
    Info:
    Macbook Pro 15'' mid 2011
    Mac OS X Mavericks / Mac OS X Yosemite
    Hard Drive: Samsung 840 Evo 250GB SSD
    8 GB Ram
    THE ISSUE:
    Every so often at a random time, at the exact moment I perform a mouse click, my macbook pro crashes.
    That instant, the screen goes dark ( like I just ripped out it's battery ) and reboots automatically, saying "your mac restarted because of a problem".
    Like I said, it's gotten more and more frequent! ( 5 times a day or more now... )
    WHAT I'VE TRIED:
    So the problem occurred in Mavericks, so I figured I'll install Yosemite ( on a new partition ) and see if it's any better.. Well it isn't...
    Same problem, same type of crash.
    Then I figured maybe it's related to my magic mouse.. So i turned it off and used a third party mouse. No luck! It also happened while using the Macbook's trackpad.
    I also haven't found anyone with a similar problem online so far, so if any of you have experienced something like this or know what might be causing it, i'd be grateful for any information!
    Best regards,
    Robert

    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    This procedure is a diagnostic test. It makes no changes to your data.
    Please triple-click anywhere in the line below on this page to select it:
    syslog -k Sender kernel -k Message CSeq 'n Cause: -' | tail | awk '/:/{$4=""; print}' | pbcopy
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window by pressing the key combination command-V. I've tested these instructions only with the Safari web browser. If you use another browser, you may have to press the return key after pasting.
    Wait for a new line ending in a dollar sign ($) to appear below what you entered.
    The output of the command will be automatically copied to the Clipboard. If the command produced no output, the Clipboard will be empty. Paste into a reply to this message.
    The Terminal window doesn't show the output. Please don't copy anything from there.

  • Movie not performing without a click

    I created a flash movie and embedded in an html. The purpose
    of the movie is menu bar. But when I open html file in browser.
    Entire swf file is look like button, (on mouse over and sign is
    coming and the button the mouse over feature which I created in
    menu button will not performing) after mouse clicking anywhere on
    movie, it will work perfectly. How I can solve this problem without
    clicking on movie.

    Its to do with a change to internet explorer. Easiest way to
    deal with it is by downloading the latest updates to flash and
    dremweaver. The one for flash has an extension with instructions on
    how to use it. When you create the flash file you create two
    javascript files which you add to your website as well.

  • Is there a way to simulate a mouse click anywhere on a screen in Dictate ?

    I'm using Dictate because of hand problems. Unfortunately, it does not seem to have the ability as supplied to simulate mouse clicks anywhere on the screen as Dragon Naturally Speaking does on the Windows side.( I do not mean by this the ability to select an item in the menu, which It does have the built in ability to do.) It can, however, so I read, be scripted to do a lot of things. Is there an Applescript out there that would allow for the simulation of mouse clicks anywhere on the screen (as opposed to just on a UI item)?

    Platform: 2.2 gHz iMac using Mac OS X 10.5.5; Dictate v. 1.2.1 Build
    Okay, so, here, after a great deal of research, is a procedure for implementing a single mouse click anywhere on the screen. Since it’s a procedure, I’m detailing each step.
    !. Download the scripting addition (sometimes known as an OSAX) xTool.sax from: http://lestang.org/osax/XTool/XTool-2.0.dmg.tgz. You will have to decompress the file (StuffIt) and double-click it to get it to unfold into a .dmg (disk image) file. In this file you will find the file Xtool.osax. Drag it into your MacHD (or whatever the name of your topmost volume is)/library/ScriptingAdditions (no spaces in the name) folder. The purpose of this is to place it into a folder where Applescript is expecting to find scripting additions. In other words, it’s hard-coded and you can’t just drop it anywhere because Applescript may not find it. Also, there may be more than one Library folder in other directories. Under 10.5.5. which I’m running, I can tell you it works where I placed it.
    The effect all of this has is that when you create your script in Dictate’s New Commands window (Script Editor), Dictate will know what the commands “click mouse’ and “position of the mouse” mean. These are not standard Applsecript commands but are additions, hence the name Scripting Additions.
    2. Start Dictate and in the File drop-down select New Command. This will take you to a window with a pane on the left with names such as Applications, Global, and several others. Click on Global (so that the command will be recognized no matter what application your are in). To the right of the pane you will see a number of commands listed by name and, underneath, a (very small) “+” (and a minus sign and a small icon). Ignore everything but the “+”. Click on the “+”.
    Below several boxes will appear: Command, Description, Context, Type.
    In Command Name type in the name you want Dictate to recognize to do the click. (I call mine Mouse click.) In Description you can type something like Single-clciks the mouse. In the Context drop-down make sure to select Global. In the Type drop-down, select Applescript.
    Paste the following into Text Edit (orTexEdit Plus,if you have that):
    click mouse {(position of the mouse), [1]}
    For reasons unknown to me, you can’t just select that text, copy, and paste it into Dictate’s Script Editor winodw. You will have to select it in Text Edit and drag it into the Source text box.
    Click on the Compile button at the left bottom. After it finishes compiling (a matter of seconds if everything is normal), click on the Run button with your mouse. If all has gone well, you will very likely see the Run button get pressed repeatedly. Take your mouse off the button so it stops blinking like mad. (The Mouse click Appplescript is repeatedly looking at the position it find itself and clicking again, and again.)
    While your mileage may vary, I have been able to simulate single mouse-click using this workaround.
    So far, I have not been able to simulate a double-click reliably. There is, I believe, an issue with the amount of time between the two clicks (a parameter of the click mouse command above which I did not go into here). For anyone out there who wants to work on that, I would be glad to hear your results. I’ve tried values up to 2000 in the DELAY parameter after the TIMES parm. Here is what the dictionary shows for this command.
    click mouse?v
    click mouse [point] : where to do the mouse click
    [times integer] : how many times you want to clik the mouse
    [delay integer] : delay between two mouse clicks
    [using primary button/secondary button/middle button] : which mouse button
    If I get this to work I will let my fellow sufferers know.
    Thanks to Hiroto and Andrew99 in particular for their help.

  • Pressing cntrl+left mouse click doesn't select multiple rows.

    Hi,
    I've got this problem after i migrated my form from 6i to 10g.
    In 6i version, cntrl+left mouse click used to work in order to select multiple rows on the screen. But, it's not working in 10g.
    Instead, Shit + left mouse click is working to select multiple rows in 10g.
    Please can someone help me out with this. I want cntrl + left mouse click to work.
    Any help will be appreciated.
    Regards
    Navnit

    Hi Pradeep,
    Thanks for your reply.
    Do you mean fmrweb.res file?
    This is the content of my res file
    9 : 0 : "Tab" : 1 : "Next Field"
    9 : 1 : "Shift+Tab" : 2 : "Previous Field"
    116 : 0 : "F5" : 3 : "Clear Field"
    38 : 0 : "Up" : 6 : "Up"
    40 : 0 : "Down" : 7 : "Down"
    33 : 0 : "PageUp" : 12 : "Scroll Up"
    34 : 0 : "PageDown" : 13 : "Scroll Down"
    69 : 2 : "Ctrl+E" : 22 : "Edit"
    10 : 0 : "Return" : 27 : "Return"
    76 : 2 : "Ctrl+L" : 29 : "List of Values"
    115 : 0 : "F4" : 32 : "Exit"
    75 : 2 : "Ctrl+K" : 35 : "Show Keys"
    83 : 2 : "Ctrl+S" : 36 : "Commit"
    118 : 1 : "Shift+F7" : 61 : "Next Primary Key"
    117 : 0 : "F6" : 62 : "Clear Record"
    38 : 2 : "Ctrl+Up" : 63 : "Delete Record"
    117 : 1 : "Shift+F6" : 64 : "Duplicate Record"
    40 : 2 : "Ctrl+Down" : 65 : "Insert Record"
    119 : 1 : "Shift+F8" : 66 : "Next Set of Records"
    1005 : 0 : "Down" : 67 : "Next Record"
    1004 : 0 : "Up" : 68 : "Previous Record"
    118 : 0 : "F7" : 69 : "Clear Block"
    66 : 2 : "Ctrl+B" : 70 : "Block Menu"
    34 : 1 : "Shift+PageDown" : 71 : "Next Block"
    33 : 1 : "Shift+PageUp" : 72 : "Previous Block"
    116 : 1 : "Shift+F5" : 73 : "Duplicate Field"
    119 : 0 : "F8" : 74 : "Clear Form"
    122 : 0 : "F11" : 76 : "Enter Query"
    122 : 2 : "Ctrl+F11" : 77 : "Execute Query"
    69 : 3 : "Shift+Ctrl+E" : 78 : "Display Error"
    80 : 2 : "Ctrl+P" : 79 : "Print"
    123 : 0 : "F12" : 80 : "Count Query"
    85 : 2 : "Ctrl+U" : 81 : "Update Record"
    121 : 3 : "Shift+Ctrl+F10" : 82 : "Function 0"
    112 : 3 : "Shift+Ctrl+F1" : 83 : "Function 1"
    113 : 3 : "Shift+Ctrl+F2" : 84 : "Function 2"
    114 : 3 : "Shift+Ctrl+F3" : 85 : "Function 3"
    115 : 3 : "Shift+Ctrl+F4" : 86 : "Function 4"
    116 : 3 : "Shift+Ctrl+F5" : 87 : "Function 5"
    117 : 3 : "Shift+Ctrl+F6" : 88 : "Function 6"
    118 : 3 : "Shift+Ctrl+F7" : 89 : "Function 7"
    119 : 3 : "Shift+Ctrl+F8" : 90 : "Function 8"
    120 : 3 : "Shift+Ctrl+F9" : 91 : "Function 9"
    113 : 0 : "F2" : 95 : "List Tab Pages"
    72 : 2 : "Ctrl+H" : 30 : "Help"
    112 : 0 : "F1" : 30 : "Help"
    I don't know what value should i enter for cntrl + left mouse click ?
    Even for shift + left mouse click, row is not there but it's working.
    Please tell if you know what row should i enter for cntrl + left mouse click in order for it to select mutliple rows?
    Regards
    Navnit

  • Terminal [ UNIX ] "mouse click" command question

    Can I emulate a left mouse click using a command in terminal? Or any freeware solutions available that would help?
    So what I wanna do is
    +open -a blabla filename+
    and then click on a specific area (like If I can tell the x,y co-ordinates to the command it would emulate the action and my application being on top would make the click)

    Let's say that myApp is the reference to your application and myItem is the item in which you want to click. Then you can do something like this
    osascript -e 'tell application "System Events" to tell myApp to click myItem at {x, y}'
    The 'at' part is optional and of course replace 'x' and 'y' with the numbers representing the x and y coordinates. For more information look at this [thread|http://forums.macosxhints.com/archive/index.php/t-36121.html]

  • Can a right mouse click be simulated from keyboard ?

    When a cell has focus and I click the right mouse button, I pop up a JPopupMenu. I would like to simulate a right mouse click using some keystroke combination from the keyboard. Is this possible ?

    You can Grab key pressed even then try to create new Mouse right click event from there somethng like that
    MouseEvent= new MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger)
    source - the Component that originated the event
    id - the integer that identifies the event
    when - a long int that gives the time the event occurred
    modifiers - the modifier keys down during event (shift, ctrl, alt, meta)
    x - the horizontal x coordinate for the mouse location
    y - the vertical y coordinate for the mouse location
    clickCount - the number of mouse clicks associated with event
    popupTrigger - a boolean, true if this event is a trigger for a popup-menu
    You can pass Id it hing that will decide wheather it is right or left click

  • Issues with mouse clicks/jumps after using CleanMyMac App.

    Since using this app. my hitherto slightly slow responding iMac has required multiple mouse clicks and is less/unresponsive.
    Anyone else used this software?
    As yet have not approached CleanMy Mac.
    I have reinstalled Mountain Lion (download) not clean install.
    Any suggestions? Is there a separate app for mouse that I can reload. Im guessing a minor chunk of code was deleted along with rubbish.
    Reg25x

    Uninstall CleanMyMac and do not reinstall it.
    CleanMyMac is one of a broad category of time- and money-wasters capable of causing system corruption that can only be rectified by reinstalling OS X, restoring from a backup, or completely erasing your system and rebuilding it from the ground up. Get rid of it and test your Mac for operation. If it does not perform normally, the possibility that Cleanmymac resulted in system corruption must be considered.
    The vast majority of Mac problems reported on this site are the direct result of having used garbage like that. Never install such junk on a Mac.

  • Diable "open dialog box" on right mouse click so I can use l mouse to advance to next slide and r mouse click to "go back."  How in PP 2010 for mac????

    I do presentations in PP10.  I am new to macair, and used to Windows.  HOW DO I DISABLE THE "OPEN DIALOG BOX ON RIGHT CLICK"?  I would like to use L mouse to advance slide, and R mouse to go back.  The default is to use R mouse to open dialog box.  I can disable this by unchecking the box in "advanced" on the PC.  How do I do it with the Mac????
    Thanks
    hacmd

    Hi Rod,
    As originally stated in my opening post, the SWF is to be inserted into an Articulate '13 slide (what I called an aggregator originally - I tried not to bring them up since I don't want the chatter about "There's your problem - using Articulate"! ).
    Recall that posting this published file to our LMS did not allow right-mouse click functionality as the flash player menu just gets in the way.
    If I insert the captivate 6 files into Articulate as a Web Object (referencing the entire folder with html, htm and assets, and then posted to our LMS, and it DOES allow RM click operations in both IE and FF (although no sound on the Captivate slide in FF). But this is not what we want to do as this introduces 2 navigation controls (the Captivate one and the Articulate Player).
    Why must anything be posted to a web server for this functionality to work?
    I am able to go into the Captivate 6's published folder, and launch the Captivate demonstration by simply double clicking on the index.html file and this works great in both FF and IE after changing the security settings for flash.
    Again - I can not believe I am the only one out there trying to use the right-mouse click feature to do a software simulation by embedding the Captivate SWF into an Articulate '13 project.

  • Edit Spry Menu Bar using Mouse Click

    Hello…
    I created a Spry Menu Bar and it's working just fine. But on phones and Tablets the submenu doesn't work because it's a mouseover, is it possible to change it to a mouse click?
    Thanks!

    Yes, but it needs a lot of JS coding to do so.
    A better solution is to use a jQuery or pure CSS menubar or visit http://www.projectseven.com/ for a commercial version

  • How do I create a new folder to use for my Outlook 365 mail account? I know with pc all I had to do was to right mouse click.

    Wondering how to create new folders for my Outlook 365 mail account. I know with pc all I had to do was to left mouse click.
    Any suggestions?

    New folder where? If you added the account in Mail app it should of created the folders to store that email automatically.
    What email program are you using?

  • Need a shortcut to "Allow pages to choose their own colors, instead of my selections above option preference" I know where it is and how to use it but I have to go through 7 mouse clicks to change it, then a few minutes later change it back. I also k

    Need a shortcut to "Allow pages to choose their own colors, instead of my selections above option preference" I know where it is and how to use it but I have to go through 7 mouse clicks to change it, then a few minutes later change it back. I also know the sequnce is alt t, alt o, alt c, alt a, then ok, ok. Got to be a way to make a one key short cut for this. I use a black background to reduce eye strain, but about 10% of the webpage I go to can't be send with black so I have to go into tools and hit 6 or 7 things to chnage it then after through with webpage have to do it all over at Not allow webpages to have own color. Very very cumbersome.
    == This happened ==
    A few times a week
    == made that way

    https://addons.mozilla.org/en-US/firefox/addon/toggledocumentcolors-198916/
    The above addon will solve your problem.
    Shortcut to toggle user color/page color :- Ctr+Shift+C

  • When I use Mail and want to paste an emailadress with a right mouse click in the adres field this doesn't work, ofcourse cmd V  works. How can I solve this

    when I use Mail and want to paste an emailadress with a right mouse click in the adres field this doesn't work, ofcourse cmd V  works. How can I solve this

    YAY!  That did it.
    Thank you so much.
    And a Very Happy and Prosperous New Year to you!
    bonnie

Maybe you are looking for