GithubHelp home page GithubHelp logo

zuzu-typ / winput Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 2.0 42 KB

winput Python extention - capture and send keyboard and mouse input on Windows

License: zlib License

Python 100.00%
input recording mouse mouse-tracking keyboard keyboard-hooks pyhook python windows extension

winput's People

Contributors

zuzu-typ 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

Watchers

 avatar  avatar

Forkers

mishav78

winput's Issues

move_mouse moves incorrect amounts.

Hi @Zuzu-Typ ,

winput.move_mouse(dx, dy) moves mouse way more than it should, with set_DPI_aware(per_monitor=True).

Here's a simple script to test it:

    first_move = 10
    second_move = 10
    winput.set_DPI_aware(per_monitor=True)
    mouse_pos = winput.get_mouse_pos()

    def move_and_measure(delta: int) -> None:
        nonlocal mouse_pos
        winput.move_mouse(delta, delta)
        new_mouse_pos = winput.get_mouse_pos()
        print(
            f"Mouse moved dx={new_mouse_pos[0] - mouse_pos[0]}, dy={new_mouse_pos[1] - mouse_pos[1]}"
        )
        mouse_pos = new_mouse_pos
        time.sleep(0.1)

    [move_and_measure(first_move) for _ in range(5)]
    print("Setting to 0, 0")
    winput.set_mouse_pos(0, 0)
    mouse_pos = winput.get_mouse_pos()
    [move_and_measure(second_move) for _ in range(5)]

Which results in

Mouse moved dx=19, dy=19
Mouse moved dx=25, dy=25
Mouse moved dx=26, dy=26
Mouse moved dx=25, dy=26
Mouse moved dx=26, dy=25
Setting to 0, 0
Mouse moved dx=26, dy=26
Mouse moved dx=25, dy=25
Mouse moved dx=26, dy=26
Mouse moved dx=25, dy=26
Mouse moved dx=26, dy=25

And if I set moves to 50:

Mouse moved dx=147, dy=148
Mouse moved dx=241, dy=240
Mouse moved dx=240, dy=241
Mouse moved dx=241, dy=240
Mouse moved dx=240, dy=210
Setting to 0, 0
Mouse moved dx=241, dy=240
Mouse moved dx=240, dy=241
Mouse moved dx=241, dy=240
Mouse moved dx=240, dy=241
Mouse moved dx=241, dy=117

Extra weird is the fact that it moves less the first time.

Cheers!

Suppress events selectively

Hi @Zuzu-Typ ,
I wonder if winput can do this, or maybe it can be added relatively easily:
In hook functions for mouse and keyboard return bool, and if false, the event would not propagate further, and will be suppressed for the rest of the system.

I'm basing this on pynput's ability to do so on windows via suppress=True globally, and via win32_event_filter as a callback like I described.

I like winput better for simplicity and responsiveness, but without this ability I can't use it properly.

[Not a] Bug: set_mouse_pos wrong coords

Hi @Zuzu-Typ ,

I'm trying to use set_mouse_pos and getting a really weird bug.
Supplying it 0 0 works well, but for 100 100 it moves the mouse to 125 125. Same applies to any coords, x=1000 moves it to 1250, 500 to 625 etc.

I see there's not much going on in winput itself, but bug exists and is easily reproducible for me (tried rebooting and shutting down everything else).

Debug confirms that coords that go into winput function are the ones I expect, not 25% higher. I confirmed coords wih ahk tooltip, and also visually - I know x and y max, I see cursor going into the corner at coords less than max, and trying to move to center results in mouse being off center.

Feature request: keyboard language detect and maybe change

Hi again @Zuzu-Typ ,

Would be cool if winput could allow to detect current keyboard layout for active window, and (though less relevant) change it.
Here's some code I've found for detection (another) and list of codes.

The idea for me is that I'll create e.g. "en-" and "fr-" keyboard layouts, and then if user wants text in french, I'll use this detect function, and if its language tag isn't "fr-XX", I'll switch until fr- is the language, and after that start typing.
Here switching can be done either by another low-level function, or by combo such as win+space (or user-specified one), so for this it's not actually that important to have a switch functionality.

If you want, I'll translate that table of languages to enum and make and MR with it, so winput can give not just the code but all other data as well.

[Misreport] (not a) Bug: alt press, and alt+key, is not registering

Hi @Zuzu-Typ ,

found a bug:

alt press (code 164) and altGr(165) pressed don't register via winput. Releases are registered.

Furthermore, when I try to press a key with one of those pressed, the key is also not registered.

Alt itself is not very critical - on hotkey alt+U, I could check alt separately via win32api when U is pressed; but keys not being detected is, as it disables any hotkeys with alt essentially.

Here's the test code:

import winput

def keyboard_callback(event: winput.KeyboardEvent) -> int:
    if event.action == 256:  # press ; 257 - release
        print(f" pressed VK code = {event.key}")
    return 0

winput.hook_keyboard(keyboard_callback)
winput.wait_messages()

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.