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

Key press simulation non-functional on macOS #372

Closed
hamishC0 opened this issue Mar 27, 2024 · 6 comments
Closed

Key press simulation non-functional on macOS #372

hamishC0 opened this issue Mar 27, 2024 · 6 comments
Labels
bug Something isn't working macOS

Comments

@hamishC0
Copy link
Contributor

hamishC0 commented Mar 27, 2024

Using the given key for key names and your comment on reddit on the subject, I tried a whole range of different descriptions for the keys to press and had no luck with any showing any function at all. I do have accessibility permissions on for Kando.

You recommended the correct listing for Cmd+Ctrl+O being "MetaLeft+Control+O". I got nothing from this so went to the docs and amended it to "MetaLeft+ControlLeft+KeyO" based on the description there. I then tried variants of these like "MetaLeft+ControlLeft+O", "MetaLeft+KeyV", "MetaLeft+V", "MetaLeft+C", "AltLeft+Space" etc. and had no response from any of these. I tried all of these and more in lowercase only also.

(and I did enable delayed to make sure it went off after the menu closed)

I could be missing something obvious but from my messing with things it sees like command and URI work perfectly while hotkey is non-functional

@Schneegans Schneegans added bug Something isn't working macOS labels Mar 27, 2024
@Schneegans
Copy link
Contributor

Hi there! I guess that this is some permission issue. Sadly, I do not have much experience in how to debug them on macOS. MetaLeft+Control+O should be working as it did on my end.

I think if you run Kando from the command line, the accessibility permission has to be given to your terminal application instead. And this may even differ if you run Kando from source via npm start or from the installed package via /Applications/Kando.app/Contents/MacOS/Kando.

How do you start Kando currently?

@hamishC0
Copy link
Contributor Author

I currently run Kando from the installed application created by running “npm run package” after install. I’ll test what happens when running from the command line or source when i get home.

@hamishC0
Copy link
Contributor Author

Okay so

Running from terminal with "npm start":

It initially gave an error asking for accessibility permissions for Terminal. Kando had it already, terminal did not. I gave terminal permission and ran again and got another error. Here's the output:

Currently focused: com.apple.finder ()
Hover item: /
Hover item: /0
Hover item: /
Select item: /0
(node:53806) UnhandledPromiseRejectionWarning: Error: Please give accessibility permissions to Kando!
    at MacosBackend.<anonymous> (/Users/hamish/kando/.webpack/main/index.js:27416:33)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/hamish/kando/.webpack/main/index.js:27327:58)
(node:53806) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise 
which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag 
`--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)

Running from terminal by activating the kando.exe in the application contents:

It worked straight away no issues. It would be an annoyance to run Kando this way however as it requires that I leave the terminal window open in the background or the app quits.

Here's the output of that:

Kando 0.5.0 is ready.
Press <Ctrl>+<Space> to open the prototype menu!
Failed to get window name for app com.apple.finder. Maybe you need to enable screen recording permissions for Kando?
Currently focused: com.apple.finder ()
Hover item: /
Hover item: /0
Hover item: /
Select item: /0
Failed to get window name for app com.apple.finder. Maybe you need to enable screen recording permissions for Kando?
Currently focused: com.apple.finder ()
Hover item: /
Hover item: /0
Hover item: /
Select item: /0

Not sure how much help this is to you but I assumed you understand far better than I what that error before shows. Also seems weird to me that running the app doesn't work, but running the .exe that is part of the app does work?

Tangential question: why is "MetaLeft+Control+O" the correct hotkey? When I looked at the link you gave that showed all the keynames it would be expected that its "MetaLeft+LeftControl+KeyO"

@Schneegans
Copy link
Contributor

Not sure how much help this is to you but I assumed you understand far better than I what that error before shows. Also seems weird to me that running the app doesn't work, but running the .exe that is part of the app does work?

Yeah, that's super weird. We will have to do some more experimentation and research here. Maybe macOS gets confused if there are multiple apps with the same name? I have no idea how it maps the permission to the executable. Btw, completely restarting the process (in this case the Terminal) will be required before the newly granted permission is really available.

However, I think there is not much we can do from the Kando side of things (I can only check if the permission was granted - this is done here).

Tangential question: why is "MetaLeft+Control+O" the correct hotkey? When I looked at the link you gave that showed all the keynames it would be expected that its "MetaLeft+LeftControl+KeyO"

There is some normalization going on here amongst other things this prefixes all single-letter key names with "Key". So both "KeyO" and "O" should be working. In fact, even "o" should work.

However, this is not yet documented and that "Command" is mapped to "Control" is plain wrong on macOS. I think it should be mapped to "MetaLeft" instead. So there's still some bugs to fix and some documentation to write 😅

@hamishC0
Copy link
Contributor Author

Okay re-testing the npm method in the terminal after restarting Kando shows that it also works there. It just doesn't work when run as an application.

@Schneegans
Copy link
Contributor

Hi there! I have changed a lot how key presses are simulated. I think there are still some limitations, but it should be much better now.

With the latest prototype version, the key format changed. You can read more about this in the documentation.

Some key presses are simply not forwarded to the system, maybe that's a limitation of the API. For instance, I cannot simulate Ctrl+Left to switch workspaces. Thankfully, there is a scripting API to explicitly pass such events to the system. In this case via osascript -e 'tell application "System Events" to key code 124 using control down'.

At some point we can check if there are more robust ways to simulate keys but for now it seems to work quite well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macOS
Projects
None yet
Development

No branches or pull requests

2 participants