Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse support schedule #31

Closed
NicoPy opened this issue Nov 19, 2016 · 9 comments
Closed

Mouse support schedule #31

NicoPy opened this issue Nov 19, 2016 · 9 comments

Comments

@NicoPy
Copy link

NicoPy commented Nov 19, 2016

Any release date for mouse event generation support ?

@boppreh
Copy link
Owner

boppreh commented Nov 20, 2016

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.

@boppreh
Copy link
Owner

boppreh commented Nov 20, 2016

Here's a basic API docs for the functions available:

API

Table of Contents

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')

[source]

Returns True if the given button is currently pressed.

keyboard.mouse.press(button='left')

[source]

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

keyboard.mouse.release(button='left')

[source]

Releases the given button.

keyboard.mouse.click(button='left')

[source]

Sends a click with the given button.

keyboard.mouse.double_click(button='left')

[source]

Sends a double click with the given button.

keyboard.mouse.right_click()

[source]

Sends a right click with the given button.

keyboard.mouse.move(x, y, absolute=True, duration=0)

[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.

keyboard.mouse.on_button(callback, args=(), buttons=('left', 'middle', 'right', 'x', 'x2'), types=('up', 'down', 'double'))

[source]

Invokes callback with args when the specified event happens.

keyboard.mouse.on_click(callback, args=())

[source]

Invokes callback with args when the left button is clicked.

keyboard.mouse.on_double_click(callback, args=())

[source]

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

keyboard.mouse.on_right_click(callback, args=())

[source]

Invokes callback with args when the right button is clicked.

keyboard.mouse.on_middle_click(callback, args=())

[source]

Invokes callback with args when the middle button is clicked.

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

[source]

Blocks program execution until the given button performs an event.

keyboard.mouse.get_position()

[source]

Returns the (x, y) mouse position.

keyboard.mouse.hook(callback)

[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.

keyboard.mouse.unhook(callback)

[source]

Removes a previously installed hook.

keyboard.mouse.unhook_all()

[source]

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',))

[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.

keyboard.mouse.play(events, speed_factor=1.0, include_clicks=True, include_moves=True, include_wheel=True)

[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 inluded
in the replay or ignored.

keyboard.mouse.replay

Alias for play.

@boppreh boppreh closed this as completed Nov 20, 2016
@NicoPy
Copy link
Author

NicoPy commented Nov 20, 2016

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

@boppreh
Copy link
Owner

boppreh commented Nov 20, 2016

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.

@glitchassassin
Copy link
Collaborator

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,

@boppreh
Copy link
Owner

boppreh commented Nov 21, 2016

@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.

@NicoPy
Copy link
Author

NicoPy commented Nov 21, 2016

so any and all suggestions are appreciated.

mouse+keyboard = mouboard or meyboard
keyboard+mouse = keyse or keyboase
😁

@boppreh
Copy link
Owner

boppreh commented Nov 21, 2016

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.

@NicoPy
Copy link
Author

NicoPy commented Nov 21, 2016

Ha Ha ! Not even afraid ! 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants