Comments (9)
@glitchassassin I understand and agree. But I'm not going down this path for the simplistic reason that I got lucky with the package name "keyboard" and I can't think of any way to describe the combo mouse+keyboard, while:
- being different enough from other active packages and libraries (there's tons of pyinput);
- being short and easy to remember ("was it keyboard_and_mouse or mouse_and_keyboard? ");
- being available on PyPI.
As you can see this is quite petty, so any and all suggestions are appreciated.
from keyboard.
It's already available as from keyboard import mouse
, and has been there for a while. It has a very similar API to the keyboard module itself, with hook
, record
, play
, press
, etc. It's not documented on the main page because I find it counter intuitive to have mouse support inside a package named keyboard.
Any suggestions on how to solve this dilemma are appreciated, as is feedback on the module itself.
from keyboard.
Here's a basic API docs for the functions available:
API
Table of Contents
- keyboard.mouse.ButtonEvent
- keyboard.mouse.DOUBLE
- keyboard.mouse.DOWN
- keyboard.mouse.LEFT
- keyboard.mouse.MIDDLE
- keyboard.mouse.MoveEvent
- keyboard.mouse.RIGHT
- keyboard.mouse.UP
- keyboard.mouse.WheelEvent
- keyboard.mouse.X
- keyboard.mouse.X2
- keyboard.mouse.is_pressed
- keyboard.mouse.press
- keyboard.mouse.release
- keyboard.mouse.click
- keyboard.mouse.double_click
- keyboard.mouse.right_click
- keyboard.mouse.move
- keyboard.mouse.on_button
- keyboard.mouse.on_click
- keyboard.mouse.on_double_click
- keyboard.mouse.on_right_click
- keyboard.mouse.on_middle_click
- keyboard.mouse.wait
- keyboard.mouse.get_position
- keyboard.mouse.hook
- keyboard.mouse.unhook
- keyboard.mouse.unhook_all
- keyboard.mouse.record
- keyboard.mouse.play
- keyboard.mouse.replay (alias)
class keyboard.mouse.ButtonEvent
ButtonEvent(event_type, button, time)
ButtonEvent.button
Alias for field number 1
ButtonEvent.count(...)
T.count(value) -> integer -- return number of occurrences of value
ButtonEvent.event_type
Alias for field number 0
ButtonEvent.index(...)
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
ButtonEvent.time
Alias for field number 2
keyboard.mouse.DOUBLE
= 'double'
keyboard.mouse.DOWN
= 'down'
keyboard.mouse.LEFT
= 'left'
keyboard.mouse.MIDDLE
= 'middle'
class keyboard.mouse.MoveEvent
MoveEvent(x, y, time)
MoveEvent.count(...)
T.count(value) -> integer -- return number of occurrences of value
MoveEvent.index(...)
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
MoveEvent.time
Alias for field number 2
MoveEvent.x
Alias for field number 0
MoveEvent.y
Alias for field number 1
keyboard.mouse.RIGHT
= 'right'
keyboard.mouse.UP
= 'up'
class keyboard.mouse.WheelEvent
WheelEvent(delta, time)
WheelEvent.count(...)
T.count(value) -> integer -- return number of occurrences of value
WheelEvent.delta
Alias for field number 0
WheelEvent.index(...)
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
WheelEvent.time
Alias for field number 1
keyboard.mouse.X
= 'x'
keyboard.mouse.X2
= 'x2'
keyboard.mouse.is_pressed(button='left')
Returns True if the given button is currently pressed.
keyboard.mouse.press(button='left')
Presses the given button (but doesn't release).
keyboard.mouse.release(button='left')
Releases the given button.
keyboard.mouse.click(button='left')
Sends a click with the given button.
keyboard.mouse.double_click(button='left')
Sends a double click with the given button.
keyboard.mouse.right_click()
Sends a right click with the given button.
keyboard.mouse.move(x, y, absolute=True, duration=0)
Moves the mouse. If absolute
, to position (x, y), otherwise move relative
to the current position. If duration
is non-zero, animates the movement.
keyboard.mouse.on_button(callback, args=(), buttons=('left', 'middle', 'right', 'x', 'x2'), types=('up', 'down', 'double'))
Invokes callback
with args
when the specified event happens.
keyboard.mouse.on_click(callback, args=())
Invokes callback
with args
when the left button is clicked.
keyboard.mouse.on_double_click(callback, args=())
Invokes callback
with args
when the left button is double clicked.
keyboard.mouse.on_right_click(callback, args=())
Invokes callback
with args
when the right button is clicked.
keyboard.mouse.on_middle_click(callback, args=())
Invokes callback
with args
when the middle button is clicked.
keyboard.mouse.wait(button='left', target_types=('up', 'down', 'double'))
Blocks program execution until the given button performs an event.
keyboard.mouse.get_position()
Returns the (x, y) mouse position.
keyboard.mouse.hook(callback)
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.
keyboard.mouse.unhook(callback)
Removes a previously installed hook.
keyboard.mouse.unhook_all()
Removes all hooks registered by this application. Note this may include
hooks installed by high level functions, such as record
.
keyboard.mouse.record(button='right', target_types=('down',))
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
.
keyboard.mouse.play(events, speed_factor=1.0, include_clicks=True, include_moves=True, include_wheel=True)
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 inluded
in the replay or ignored.
keyboard.mouse.replay
Alias for play
.
from keyboard.
It's already available as from keyboard import mouse, and has been there for a while.
Sorry for that. As on the main page, it is written "Mouse support coming soon." I didn't look further.
Thanks
from keyboard.
No need to apologize, the mouse submodule is supposed to hidden. Otherwise people will start depending on its API and have trouble when it's moved somewhere else, like a separate package.
And thank you for your interest in this library. Every piece of feedback makes it better.
from keyboard.
For what it's worth, I think it makes perfect sense to keep mouse & keyboard functionality together in the same library. System APIs usually tap both kinds of devices (at least for Windows). Why not Python modules?
Cheers,
from keyboard.
so any and all suggestions are appreciated.
mouse+keyboard = mouboard or meyboard
keyboard+mouse = keyse or keyboase
😁
from keyboard.
Don't tempt me. I'm going to register them on PyPI as aliases for this package, with credits to you, then we can both share the embarrassment.
from keyboard.
Ha Ha ! Not even afraid ! 😛
from keyboard.
Related Issues (20)
- Capture the activation of a hotkey while other keys are being pressed HOT 1
- Sometimes the keys are not pressed
- Using exit(0) inside on_press_key() lambda doesn't exit the program
- Keys like "D" Counting as other keys HOT 1
- keyboard.suppress blocks keyboard.is_pressing
- TOO MANY dependencies HOT 3
- suppress=True breaks shift-click selection in Notepad, Explorer
- suppress=True breaks Windows Start Menu HOT 3
- Key name '~' in not mapped to any known key
- 'right alt' and 'left alt' parsable hotkeys behaves the same as the 'alt' parsable hotkey on Windows
- suppress=True doesn't work with read_hotkey and on_release_key HOT 1
- How to stop `Keyboard.hook` hooking `keyboard.send` or `keyboard.write`?
- Alt Down not detected with Streamdeck
- Returns upper and lower cases on Windows but only lower cases on Linux
- An OSError when the device is unplugged on RaspberrypiOS HOT 2
- Suddenly not working in mac os
- Periodicaly produce a TypeError: object of type 'NoneType' has no len()
- Cannot hold a key
- 'LMB + Ctrl' mulfunctions when `suppress = True`
- German and English Keyboard. Mixed letters (Z<-->Y)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keyboard.