Code Monkey home page Code Monkey logo

mouse's Introduction

mouse

Take full control of your mouse with this small Python library. Hook global events, register hotkeys, simulate mouse movement and clicks, and much more.

Huge thanks to Kirill Pavlov for donating the package name. If you are looking for the Cheddargetter.com client implementation, pip install mouse==0.5.0.

Features

  • Global event hook on all mice devices (captures events regardless of focus).
  • Listen and sends mouse events.
  • Works with Windows and Linux (requires sudo).
  • Works with MacOS (requires granting accessibility permissions to terminal/python in System Preferences -> Security & Privacy)
  • Pure Python, no C modules to be compiled.
  • Zero dependencies on Windows and Linux. Trivial to install and deploy, just copy the files.
  • Python 2 and 3.
  • Includes high level API (e.g. record and play.
  • Events automatically captured in separate thread, doesn't block main program.
  • Tested and documented.

This program makes no attempt to hide itself, so don't use it for keyloggers.

Usage

Install the PyPI package:

$ sudo pip install mouse

or clone the repository (no installation required, source files are sufficient):

$ git clone https://github.com/boppreh/mouse

Then check the API docs to see what features are available.

Known limitations:

  • Events generated under Windows don't report device id (event.device == None). #21
  • To avoid depending on X the Linux parts reads raw device files (/dev/input/input*) but this requires root.
  • Other applications, such as some games, may register hooks that swallow all key events. In this case mouse will be unable to report events.

API

Table of Contents

ButtonEvent(event_type, button, time)

Alias for field number 1

Return number of occurrences of value.

Alias for field number 0

Return first index of value.

Raises ValueError if the value is not present.

Alias for field number 2

= 'double'
= 'down'
= 'left'
= 'middle'

MoveEvent(x, y, time)

Return number of occurrences of value.

Return first index of value.

Raises ValueError if the value is not present.

Alias for field number 2

Alias for field number 0

Alias for field number 1

= 'right'
= 'up'

WheelEvent(delta, time)

Return number of occurrences of value.

Alias for field number 0

Return first index of value.

Raises ValueError if the value is not present.

Alias for field number 1

= 'x'
= 'x2'
= '0.7.1'

[source]

Returns True if the given button is currently pressed.

[source]

Presses the given button (but doesn't release).

[source]

Releases the given button.

[source]

Sends a click with the given button.

[source]

Sends a double click with the given button.

[source]

Sends a right click with the given button.

[source]

Scrolls the wheel delta clicks. Sign indicates direction.

[source]

Moves the mouse. If absolute, to position (x, y), otherwise move relative to the current position. If duration is non-zero, animates the movement. The fps of the animation is determined by 'steps_per_second', default is 120.

[source]

Holds the left mouse button, moving from start to end position, then releases. absolute and duration are parameters regarding the mouse movement.

[source]

Invokes callback with args when the specified event happens.

[source]

Invokes callback with args when the left button is clicked.

[source]

Invokes callback with args when the left button is double clicked.

[source]

Invokes callback with args when the right button is clicked.

[source]

Invokes callback with args when the middle button is clicked.

[source]

Blocks program execution until the given button performs an event.

[source]

Returns the (x, y) mouse position.

[source]

Installs a global listener on all available mouses, invoking callback each time it is moved, a key status changes or the wheel is spun. A mouse event is passed as argument, with type either mouse.ButtonEvent, mouse.WheelEvent or mouse.MoveEvent.

Returns the given callback for easier development.

[source]

Removes a previously installed hook.

[source]

Removes all hooks registered by this application. Note this may include hooks installed by high level functions, such as record.

[source]

Records all mouse events until the user presses the given button. Then returns the list of events recorded. Pairs well with play(events).

Note: this is a blocking function. Note: for more details on the mouse hook and events see hook.

[source]

Plays a sequence of recorded events, maintaining the relative time intervals. If speed_factor is <= 0 then the actions are replayed as fast as the OS allows. Pairs well with record().

The parameters include_* define if events of that type should be included in the replay or ignored.

mouse's People

Contributors

boppreh avatar dorinclisu avatar heck-r avatar mrqubo avatar redstoneleo avatar samitumarov avatar timgates42 avatar ventorvar avatar vvzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mouse's Issues

Wacom support

On Linux, Wacom is sending different button codes than a regular mouse and so all events get the '?' button argument. The events are sent for everything as a button press (just hovering near the surface with pen or finger is also a separate click event). Is there any way to get not the raw codes from Wacom but the higher-level button codes translated by the driver?

Please allow BSD OSes

For FreeBSD, I added this patch:

-elif _platform.system() == 'Linux':
+elif _platform.system() == 'Linux' or _platform.system() == 'FreeBSD':

But you should allow the whole set of BSDs: FreeBSD/OpenBSD/NetBSD/FragonflyBSD.

Mouse movements/hooks work, but mouse clicks do not. (kubuntu cosmic 18.10, KDE/Plasma)

Title.

The test case is as simple as:

~/mouse (master|✔) $ sudo python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mouse
>>> mouse.move(50, 50) ## works
>>> mouse.click() ## nothing happens?
>>> ## no error

(alongside this, mouse.wait() and mouse.record() work, but mouse.replay() will replay movements but not clicks)

(the mouse directory is a fresh clone of this repository)

I'm not intimately familiar with how mouse interacts with linux on an i/o level, so i'm going to attempt to provide as much useful information as possible. Let me know what specific information you'd need about my environment.

This is a relatively vanilla installation of kubuntu:

~ $ apt list --installed | grep input

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

inputattach/cosmic,now 1:1.6.0-2 amd64 [installed,automatic]
libinput-bin/cosmic,now 1.12.1-1 amd64 [installed,automatic]
libinput10/cosmic,now 1.12.1-1 amd64 [installed,automatic]
libwinpr-input0.1/cosmic,now 1.1.0~git20140921.1.440916e+dfsg1-15ubuntu1 amd64 [installed,automatic]
xinput/cosmic,now 1.6.2-1build1 amd64 [installed,automatic]
xserver-xorg-input-all/cosmic,now 1:7.7+19ubuntu8 amd64 [installed,automatic]
xserver-xorg-input-libinput/cosmic,now 0.28.1-1 amd64 [installed,automatic]
~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.10
Release:        18.10
Codename:       cosmic
~ $

With the standard KDE window manager.

Nothing appears in dmesg except for the input: Virtual Keyboard as /devices/virtual/input/input## messages.

cannot figure out how to use mouse.on_double_click on Windows

With the following code, I think the sayHello function should print out something when double clicking left mouse button , but none , so what's wrong here ?

import mouse


def sayHello():
    print(mouse.get_position(),'sayHello')
mouse.on_double_click(sayHello)  # lambda: print(11111111111) callback, args=()

mouse.wait(button='left', target_types=('double',))

Tested on Win7 32 bit, Python 3.5.2

How can I convert below Autohotkey algorithm to python script?

First of all thank you for developing this tool. In Windows I used an Autohotkey script to use a mouse with worn-out switches. As far as I understand it mouse tool can do it.
I used to run the mouse with the below script.

 LButton::  ;blocks  the left button event completely
 If (A_TimeSincePriorHotkey < 100) ;detects if a faulty hyperclick event occured
 Return ; if it's a faulty  hyperclick, it keeps blocking the left button events
 sendinput {LButton down} ; else send decent simulated click down event
 KeyWait, LButton ; waits for another button event
 sendinput {LButton up} ; send simulated button up event
 Return

It simply filters repititive hyper click events.
It works very well in Windows but Linux missing such a tool.

Algorithm should be:

 block  the left button event completely
 if faulty repititive hyperclick events occur less than 200 ms, return
 (if it's a faulty  hyperclick,  keep blocking the left button events)
 else send decent simulated click down event
 wait for another button event which is higher than 200ms timeout
 send simulated button up event
 return

Is it possible with this tool?
Autohotkey script

Issue with specific mouse

Mouse wheel on my logitech g50d has a sort of half click which throws an error in "low_level_mouse_handler" in the "mouse/_winmouse.py" file. Made a hack fix by setting event to None before the "if wParam..." and only putting to the queue when not None. basically it just ignores when it sees a button it can't handle.

mouse.on_double_click not working

Hi,

I have the issue where callback passed to mouse.on_double_click isn't invoked.

I took a quick peek and it seems that handler method defined in mouse.on_button gets called twice successively. Each ButtonEvent passed to the handler has button = 'left' and event_type = 'down' members, instead of button = 'left' and event_type = 'double' which the handler checks for.

This is the code I'm talking about.

def on_button(callback, args=(), buttons=(LEFT, MIDDLE, RIGHT, X, X2), types=(UP, DOWN, DOUBLE)):
    """ Invokes `callback` with `args` when the specified event happens. """
    if not isinstance(buttons, (tuple, list)):
        buttons = (buttons,)
    if not isinstance(types, (tuple, list)):
        types = (types,)

    def handler(event):
        if isinstance(event, ButtonEvent):
            if event.event_type in types and event.button in buttons:
                callback(*args)
    _listener.add_handler(handler)
    return handler

I'm a little busy at the moment, but if I find time I'll make an attempt at fixing this.

Mouse moves but does not visually move and cannot click.

So I was testing this out on my ubuntu virtualbox vm, running in python3. From the terminal I ran the mouse.move(x,y,absolute,time) method, which did not seem to work. However, I noticed that get_position was being changed and the shape of my cursor changed when it would be moving over text. However the position immediately went back as soon as I move the cursor, even by one pixel. I then tried the click method, which simply did not work, and did not work with the callback for clicking either, although if I manually clicked, the callback correctly triggered.

implemented the on_released event

In https://github.com/boppreh/mouse/blob/master/mouse/__init__.py
I implemented the on_released event as following , please considering whether if it could merged into the project

def on_released(callback, args=()):
    """ Invokes `callback` with `args` when the left button is clicked. """
    return on_button(callback, args, [LEFT,RIGHT], [UP])

mouse 0.7.0 - mouse polling hate 125-1000hz

Hello guys!

I installed mouse 0.7.0 by pip install mouse.

This mouse api works fine on an aplication designed to mouses 125hz, but i cant use on 1000hz polling rate because it make slow moves.

how can i "import mouse" and hook it to a 1000hz mouse? is it possible?

the code i use win32api.mouse_event and mouse.is_pressed.

Sorry my bad english.

I thank any help.

mouse.record crashes in virtualbox linux guest with captured mouse

Steps to recreate

Create Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "bstoots/xubuntu-16.04-desktop-amd64"
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # CoW
    vb.linked_clone = true


    # More memory for gui operations
    vb.memory = "1024"
  end
end

run vagrant up

login and pw is vagrant

install python3 and mouse

sudo apt install python3-pip python3-dev python3-dbg
sudo -H pip3 install mouse

** record**
sudo python3 -c "import mouse; print(mouse.record())"


You can run it with sudo gdb --args python3 -c "import mouse; print(mouse.record())" to analyze the stack. I didn't get very far as the python interpreter is optimizing out stuff.

delay error and mouse error

def ads_up():
    print('one22')
    mouse.unhook_all()
    print(mouse.is_pressed(button='right'))
    #mouse.on_button(ads_down, buttons=('right'), types=('down'))

def ads_down():
    print('one')
    mouse.unhook_all()
    mouse.release()
    mouse.click(button='right')
    mouse.press(button='right')
    mouse.release(button='right')
    time.sleep(1)
    print(mouse.is_pressed(button='right'))
    #mouse.press(button='right')
    mouse.on_button(ads_up, buttons=('right'), types=('up'))
    print('test')
   

mouse.on_button(ads_down, buttons=('right'), types=('down'))

one
True
test
one22
False

it always says its true release(button='right') does not work.
it also checks everything at the same time and does not matter if I put a #time.sleep(88)
I'm trying to make a ads for a game
it will always loop if I try and make it check as I show and I don't want it to
If I uncomment out mouse.press(button='right') mouse.on_button(ads_up, buttons=('right'), types=('up')) will still run

Got the code to work.

def ads_up():
    print('restarting')
    time.sleep(0.5)
    mouse.wait(button='right', target_types=('down'))
    ads_down()

def ads_down(buttons=('right'), target_types=('down')):
    time.sleep(0.2)
    if mouse.is_pressed(button='right') is True:
        print(mouse.is_pressed(button='right'))
        print('cool')
        mouse.click(button='right')
        mouse.click(button='right')
        print('cool2')
        print('waiting')
        mouse.wait(button='right', target_types=('up'))
        print('done')
        ads_up()
    else:
        mouse.click(button='right')
        ads_up()
aps_down()

How do I make this work with tkinter? soon as there is the mouse.wait it breaks the gui.

AttributeError: module 'mouse' has no attribute...

Hello,

Using any mouse functions generates for example:

import mouse
def test():
print('a')
mouse.on_click(test)

AttributeError: module 'mouse' has no attribute 'on_click'

This error shows up with any mouse function

Im using python 3.7.0 on windows 7. I see that mouse is installed under pip list. 'Import mouse' does not generate any error.

Remove claim to support MacOS X from setup.py

It's kind of highly misleading to claim MacOS X support in setup.py while the code does in fact not support it. Other people might get confused as well. So removing this bit would be only fair:
Operating System :: MacOS :: MacOS X

See also #30.

mouse.is_pressed() gets stuck

Seemingly randomly, mouse.is_pressed() gets stuck.

With just this:
leftm = mouse.is_pressed(button='left') print(leftm)

Try clicking and unclicking ~25 times, soon after it'll stop accepting input and get stuck at either True or False.

OSError: Unsupported platform 'Darwin'

I'm getting the following error message:

Traceback (most recent call last): File "count_keystrokes.py", line 1, in <module> import keyboard, mouse File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mouse/__init__.py", line 51, in <module> raise OSError("Unsupported platform '{}'".format(_platform.system())) OSError: Unsupported platform 'Darwin'

mouse.on_click() doesn't work and terminates the program

Hi,
I'm trying to use mouse.on_click() on Arch Linux and it doesn't work. It terminates the program as soon as i click without calling the callback function and raising any issue.
Here is my simple code :

import mouse
def test():
    print('cc')

mouse.on_click(test)
mouse.wait()

mouse.is_pressed("left") trigger only one time

while True: print(mouse.is_pressed("left"))

When I press the left mouse button, I get a true until I release the mouse button. If I repeat this again, then I only get False.

Edit:
I could notice when I move a window that I get True when I release a False. If I move the same window again, I get a false. It is all random.

mouse Modul Version 0.7.1
Tested with Python 3.7 x64 and 3.8 x32.
I have Windows 10 x64.

_winmouse.wheel() scroll down calibration

mouse/mouse/_winmouse.py

Lines 195 to 198 in f59fdc8

def wheel(delta=1):
code = simulated_mouse_codes[(WHEEL, VERTICAL)]
user32.mouse_event(code, 0, 0, int(delta * WHEEL_DELTA), 0)

By default scroll wheel event in _winmouse.wheel() isn't registering when delta=-1/120 or delta=-2/120.
Seems to be a Windows issue.
It can easily be checked by running in Windows 10, Python 3.7.0:

import time
import mouse

delta = -2/120
for _ in range(100):
	mouse.wheel(delta)
	time.sleep(0.01)

Code does nothing even though it should scroll down a small amount.
Changing delta to -3/120 works and has the same speed as delta=+1/120.
So the -1 and -2 are not used and -3 would be as fast as +1.
A proposed fix:

def wheel(delta=1):
    code = simulated_mouse_codes[(WHEEL, VERTICAL)]
    if delta >= 0:
        user32.mouse_event(code, 0, 0, int(delta * WHEEL_DELTA), 0)
    else:
        # First 2 negative values are unused.
        user32.mouse_event(code, 0, 0, int(delta * WHEEL_DELTA) - 2, 0)

Now delta=-1/120 would work and have the same speed as delta=+1/120 as expected.

Hook additional mouse buttons.

Is there a way to add other mouse buttons such as mouse button 10-15 to use them in hooks and combinations?

When I tried to record them, the mouse event comes with button = '?'. ex:
[MoveEvent(x=332, y=663, time=1582341419.117103), ButtonEvent(event_type='down', button='?', time=1582341419.385115), ButtonEvent(event_type='up', button='?', time=1582341419.516075)]

move on the touchpad without click, wrongly regard MoveEvent as ButtonEvent

Run the script in Ubuntu(with sudo):

events = []
mouse.hook(events.append)
while 1:
    mouse._listener.queue.join()
    for event in events:
        print(event)
    del events[:]
    print(mouse.get_position()) 
    time.sleep(0.25)

When I just move on the touchpad without click, regard MoveEvent as unknown ButtonEvent:

ButtonEvent(event_type='down', button='?', time=1581923482.258478)
(1991, 859)
ButtonEvent(event_type='down', button='?', time=1581923482.258478)
(1985, 860)
ButtonEvent(event_type='up', button='?', time=1581923484.208888)
(1627, 1109)
...

But when I move mouse by TrackPoint, it goes well:

MoveEvent(x=872, y=672, time=1581930872.364979)
(874, 671)
MoveEvent(x=872, y=672, time=1581930872.414934)
(874, 671)
...

But in win10, run the same script, move on the touchpad could capture the MoveEvent

mouse.move not moving to correct coordinates

When using mouse.move(), the coordinates are not correct, ie: if I have this:

mouse.move(0, 1080, absolute=True)
print(mouse.get_position())

it should go to the bottom left (which it does) yet getting the mouse position reveals its actually 863.
If I then do mouse.move(0, 863, absolute=True), it puts me at the bottom left again, further testing reveals it isn't going to the correct spot. This also happens on the x-axis, giving me a max of 1535.

Relative Mouse Coords in Window

Is there a way to deal with mouse coordinates relative to the active window frame, rather than the monitor? (In the context of functions like mouse.get_position() and mouse.move())

Mouse coordinates do not replay correctly with display zoom on windows 10

On windows 10, a display can have a zoom setting (e.g., 200%). The mouse.record() and mouse.play() seem to not use consistent mouse coordinates. This means that when the events are played, they do not reproduce the recorded mouse motions. Moreover, if mouse coordinates move across displays, then I cannot tell which scaled mouse coordinate system is in effect.

Any ideas about this?

Calling mouse.double_click inside callback of mouse.on_click leads to infinite recursion

Calling mouse.double_click inside callback of mouse.on_click leads to infinite recursion, so better to distinguish between a mouse click and a double click

I don't know if this issue is related to this post

My test code as follows, be sure to save all your unsaved work and you can fore a stop to a running Python program before test the issue , or else the infinite recursion mouse clicks might cause some problems to your work!


import mouse
import time



def onMouseClicked():
     print('1 single click')
     mouse.double_click(button='left')  #
     print('2 double click')
    # time.sleep(1000)
#     mouse.click(button='left')  #
#     print('3 single click')
#     mouse.unhook_all()
#mouse.on_double_click(onMouseClicked)
mouse.on_click(onMouseClicked)
mouse.wait(button='right', target_types=('double', 'up'))  #

Simple example - Runtime failure

Hello,
I would like to get starting writing a program to automate mouse movement.
Here's a script attempting to click all the points in a 100x100 px box. But I am encountering runtime errors.

Could you possible write a small example of how I would accomplish basic movement and clicking? My methodology must be off.

Much thanks!

import mouse
import time

t_end = time.time() + 20
while time.time() < t_end:
    for i in range(100):
        for j in range(100):
            #print(mouse.get_position())
            mouse.move(i,j,absolute=True)
            mouse.click("left")

Sending mouse events doesn't work.

Everything that simulate mouse event doesn't work, except on positioning/moving the cursor.
Listening to mouse event works fine.
My machine running on Debian 4.19.28-2 (2019-03-18) i686 GNU/Linux.

Pickling keyboard/mouse events unstable?

I have noticed that when I pickle a list of events, and then later try to load the pickle files, that the original list of events is not always recoverable? Are the events not pickle-able in this way?

OS X Support

Opening this for tracking purposes, I'll fork this and start working on support for Mac.

DirectX / DirectInput support

Hey,

I tested mouse 0.7.0 on a DirectX game, and it seems as if click() and press() work fine, albeit with hiccups in performance. However, move() does not work within the game, though it does outside of the game window.

I'm fairly certain this is due to the game's use of DirectInput, and from what I've seen with Python DirectX mouse support, many other users have been having a similar issue.

Is there any workaround that will allow this library to work with DirectX, or anything else that you can suggest?

Segmentation Fault - Arch Linux

I'm running the following code in python 3.6.3 in an Arch linux OS:

import mouse

def say_hello():
    print('hello')
    
mouse.on_middle_click(say_hello)
mouse.wait()

When I run this script, it waits for the middle mouse button to be pressed. However, if I move the mouse, I get an error: "Segmentation fault".

Please push new PyPI release

The current stable version still suffers the segfault problem. The current master is more stable (for me) than current stable.
It would be awesome if there would be an update. If there are any concerns, maybe consider publishing a pre release version.

on_double_click on Linux

Any idea on how to make on_double_click work with Linux?

`import mouse
def test():
print('cc')

mouse.on_double_click(test)
mouse.wait(mouse.RIGHT)`

This doesn't seem to work.

ValueError: list.remove(x): x not in list

import mouse
def onMouseClicked():
    mouse.unhook(onMouseClicked)
    mouse.double_click() 
    mouse.click()

mouse.on_click(onMouseClicked)
mouse.wait(button='right', target_types=('double', )) 
    

caused the exception

Traceback (most recent call last):
  File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\_generic.py", line 22, in invoke_handlers
    if handler(event):
  File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\__init__.py", line 164, in handler
    callback(*args)
  File "D:\BaiduYunDownload\编程\Python\WindowsMouseHook.py", line 7, in onMouseClicked
    mouse.unhook(onMouseClicked)
  File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\__init__.py", line 221, in unhook
    _listener.remove_handler(callback)
  File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\_generic.py", line 72, in remove_handler
    self.handlers.remove(handler)
ValueError: list.remove(x): x not in list

How can I do mouse.click() action faster?

Now mouse.click() action need about 10-20ms, this API is faster than pynput(20ms) and pyautogui( 100ms). It is awesome. But I want to write a fishing bot to some games. 10-20ms means I cannot catch the fish in 100% probability. So how can I do mouse.click() action faster?

Listening on Linux crashes if the first thing I do is move on touchpad

I wasn't sure how to test if this package works (looks cool, though), but by while looking at the code I've noticed, that you can run the package and it'll start... well I'm not exactly sure what __main__.py:27 does... Run events from input even though I don't have any stdin?

So anyway, I prepared a Python 3.6 virtualenv, and ran the package like this:

sudo /home/butla/.virtualenvs/ble/bin/python -m mouse

I've touched the touchpad and immediately saw this error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/butla/.virtualenvs/ble/lib/python3.6/site-packages/mouse/__init__.py", line 69, in listen
    _os_mouse.listen(self.queue)
  File "/home/butla/.virtualenvs/ble/lib/python3.6/site-packages/mouse/_nixmouse.py", line 98, in listen
    if event is None:
UnboundLocalError: local variable 'event' referenced before assignment

After that, nothing was happening anymore when I interacted with the touchpad.

But I did a few more tries, and on one the first thing I did was to press the left button under the touchpad - then everything started working and I was seeing a stream of events:

{"event_type": "down", "button": "left", "time": 1515361548.220245, "event_class": "ButtonEvent"}
{"event_type": "up", "button": "left", "time": 1515361548.270112, "event_class": "ButtonEvent"}
{"event_type": "up", "button": "left", "time": 1515361548.270112, "event_class": "ButtonEvent"}
{"event_type": "up", "button": "left", "time": 1515361548.270112, "event_class": "ButtonEvent"}
{"event_type": "up", "button": "left", "time": 1515361548.270112, "event_class": "ButtonEvent"}
{"event_type": "up", "button": "left", "time": 1515361548.270112, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}
{"event_type": "down", "button": "?", "time": 1515361548.886853, "event_class": "ButtonEvent"}

Even moving on touchpad was OK.

After a short (print) debugging session, I've noticed that when I move the touchpad, the type variable is equal to 3, which means EV_ABS, which isn't accounted for in the if/else block at _nixmouse.py:86. So, is this just me, or did I found a bug?

I don't know if that's related somehow, but I have Alienware 15 R3, and I heard that some people had weird Linux touchpad driver issues on other Alienware models in the past.

Last bit of debug info - I'm using Kubuntu 17.10.

Segmentation Fault when trying to use mouse.record(button='F2')

Linux j-pc 4.4.0-83-generic #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
python 3.5
mouse Version: 0.7.0

my code

import mouse
def run():
    start_stop_record = 'F2'
    print('Press {} to start or stop mouse recording'
          .format(start_stop_record))
    events = mouse.record(button=start_stop_record,)
run()

edit: I realize now that the button is a mouse button, so something like 'left' or 'right' would be valid. Core problem still exists though I believe.

traceback from gdb

j@j-pc ~/_Github-Projects/misc_scripts $ sudo gdb python3
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...(no debugging symbols found)...done.
(gdb) run misc_scripts/record_and_play_mouse_macro.py 
Starting program: /usr/bin/python3 misc_scripts/record_and_play_mouse_macro.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Press F2 to start or stop mouse recording
[New Thread 0x7ffff5675700 (LWP 27441)]
[New Thread 0x7ffff4e74700 (LWP 27442)]
[New Thread 0x7fffeffff700 (LWP 27443)]

Thread 3 "python3" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff4e74700 (LWP 27442)]
0x00007ffff43659d0 in XDefaultRootWindow () from /usr/lib/x86_64-linux-gnu/libX11.so.6
(gdb) 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.