-
Notifications
You must be signed in to change notification settings - Fork 435
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
OS X support possible? #11
Comments
The codebase is organized to easily allow supporting new systems. It is cleanly divided in frontend (numerous methods, flexible calls, OS independent, high level) and backend (e.g. Unfortunately I have zero access or experience with any Apple machine. I would gladly accept contributions, but I'm afraid I cannot provide OS X support myself. |
So, no news on this issue. Unfortunately I still don't have access to any OS X computer. I'll have to close this issue for the time being, but I would be extremely happy if somebody stepped in with a pull request. Mimicking the API of the |
I'm reopening this issue in hopes of attracting contributors. Suggestions on how to add OS X support, part 1 (part 2)To integrate an OS X module two things are needed:
A backend is just a module that exposes four low-level functions, namely:
These four functions will be used by the higher-level part of the library, where functions like Keeping in line with the rest of the library, it would be best if this module had no dependencies, required no compilation step and supported internationalized layouts, but I'm willing to compromise because having something is better than nothing. Feel free to use as much While I cannot help with any OS X specific code I would be extremely glad to answer any questions or clarify any points that could help you implement it. |
(drive-by comment) We have some Python only code (depending on pyobjc) for multimedia keys on osx: https://github.com/quodlibet/quodlibet/blob/master/quodlibet/quodlibet/mmkeys/osx.py maybe it helps as a starting point... |
Suggestions on how to add OS X support, part 2 (part 1)Part 1 has some details on how to interface with the rest of the library. Now, how would you actually implement that? I see three main possibilities:
|
This may be helpful: https://github.com/willwade/PyUserInput/blob/master/pykeyboard/mac.py |
and this.. SavinaRoja/PyUserInput#39 For the record (having looked at this myself..) I don't recommend @boppreh suggestion of 2 - and I don't think 3 would be a massive gain over 1. I think you are stuck with ctypes. Its fast and it works... |
@boppreh, I've just acquired a Macbook and am in the process of adding OSX support to my automation library. I'll see what I can put together for |
Awesome, that's great news. If you need anything please don't hesitate to contact me. |
The PyUserInput code is licensed under the GPL, so I don't want to just copy-paste it into this project. Currently studying it for re-implementation. |
Looks like the API specified above may be incomplete. I added a method I have basic key mapping and key emulation functionality implemented. Working on the event listener. It looks like listening to global keypresses will require root. |
Event listener set up. I also completed the mouse back-end (I think). I'll do some more testing and then submit a pull request. |
@glitchassassin do you have a fork I can take a look at and maybe assist with? I see your actively working on it. |
Sure, this fork should be up to date with all my changes. The testing that I have done so far seems to have been successful. Just working on translating the test cases for my project so I can verify that everything I rely on works well. Let me know if you find any issues! |
Would you mind enabling issues in the fork? |
Done. |
Running into a hitch with double-clicking and dragging. In OSX, both are distinct actions that require specific flags to be set. It's not as simple as "mouse down, mouse move, mouse up". I am now tracking mouse button state, so if a mouse button is held down, move_to triggers a drag event instead of a mouse move event. Double-clicking might be a little more complicated. Checking. |
@glitchassassin We could also adapt the other platforms to behave more like this, and let them simulate the appropriate actions when they receive a "composite" event. |
I've been able to implement the "smart" event detection to send drag-and-drop events and double-click events. I'm doing further testing to make sure it's robust, but I think this will avoid restructuring the other platform handlers. |
Fixed all the issues my tests uncovered. Waiting to see if @bandrel finds any more, and then I'll create a pull request. |
2 month has passed, any progress? |
Aha! I have a problem with using
I'm running my script with |
Looks like you're using an older version of the If you're already on 0.10.0, please post the output of Thanks! |
Something weird happened, once I upgrade the I was planning to make a minimal example to reproduce the problem, but it says import sys
import keyboard
if __name__ == '__main__':
keyboard.add_hotkey("alt+shift+c", lambda: print('hello'), suppress=True)
keyboard.wait() |
I don't have OS X to test, but your code seems correct and is working as expected in Windows and Linux. Also, I would suggest checking if your system is ok and reinstalling the package from scratch.. |
Also, make sure you don't have any python programs or folders named |
Aha! The filename of this small example was |
The hot key works if I run it from python like: One problem left with me, is |
No problem, glad to help.
Thank you.
I have never used a mac; is there a well known 1:1 correspondence? If yes, I can easily add aliases to those names. The downside is that every event name is normalized against these aliases, so hooked events will always report as If you prefer, feel free to open a new issue about this. Or continue posting here. I don't mind, except that I can't mark it as "solved" anymore because this is a closed issue. |
I will try to run then same file under Windows when I can. |
When I use RDP from my Mac to a Windows machine, command automatically maps to the Windows key; option maps to the alt key; and control maps to the ctrl key. I think it's safe to say that's the established pattern. |
Ok then, I'll setup the aliases when I get home. |
v0.10.4 should have the Mac->Windows aliases. |
Do you think an OS X port would be possible?
The text was updated successfully, but these errors were encountered: