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

Keyboard shortcuts sometimes stop working (Secure Input) #157

Closed
stevemartina-salesforce opened this issue Feb 11, 2020 · 95 comments
Closed
Labels
bug Something isn't working need breakthrough Need a breakthrough idea to move forwards unreproducible Need help from the author to reproduce the issue
Milestone

Comments

@stevemartina-salesforce

v2.3.2 often doesn't fire - Alt-Tab invokes the standard MacOS switcher, except releasing the keys doesn't dismiss the dialog. I need to click on an icon or press Enter to dismiss.
Alt keys is Cmd, Tab is 48, theme is MacOS.
MacOS Mojave 10.14.6

Normally restarting Alt-Tab does the trick, but lately it doesn't change anything.

@lwouis
Copy link
Owner

lwouis commented Feb 12, 2020

Hi @stevemartina-salesforce! Thank you for sharing this feedback!

It seems to be some kind of OS-level priority about who gets to register the global shortcut. I will say that the current implementation is naive, and exhibits some limitations: #133, #17, #50.

I would suggest 2 approaches:

  • If you want a quick fix: could you please investigate a bit more, and try to guess what the root cause is here? The Keyboard handling is pretty short. It's not the easiest though since it's a swift bridge over a C API. You may want to just put some breakpoints around that file and see how the code flows while you reproduce the issue.
  • If you can wait a few weeks: I'm waiting on Modifier-only shortcut Kentzo/ShortcutRecorder#114 to be implemented so that I can replace the naive code with the robust ShortcutRecorder library. This will most likely fix any issue such as what you are experiencing here.

@lwouis lwouis added bug Something isn't working unreproducible Need help from the author to reproduce the issue labels Feb 12, 2020
@kingfisher77
Copy link

Same here

  • AltTab 2.3.4
  • Catalina 10.15.3 (19D76)

@lwouis lwouis added this to the v4 milestone Mar 11, 2020
@kungpaogao
Copy link

kungpaogao commented Mar 29, 2020

I'm on AltTab 3.2.1 now and Catalina 10.15.4, and the issue of not firing seems to occur after my computer wakes from sleep.

EDIT: looked through other issues, seems to be related to #176.

EDIT 2: I let my computer sleep overnight, and AltTab still works this morning... maybe it's not related to sleep.

@lwouis
Copy link
Owner

lwouis commented Apr 1, 2020

@kungpaogao I tried also to sleep/wake and it didn't stop AltTab from working.

I think there is a big lack of clarity as to what behavior is exhibited with this issue.

From @stevemartina-salesforce, I understand that he presses the AltTab shortcut, but AltTab doesn't show up. Instead the built-in app-switcher does. Is AltTab opened at this point? I could imagine it crashed for example, which would explain why the built-in app-switcher is showing instead. That wouldn't explain why releasing the cmd key fails at that point. That could be a second, different issue, like AltTab not properly releasing global shortcuts on crash for example. It seems suspiciously similar to #175.

@kungpaogao is the above behavior exactly the same for you? Could you elaborate on the symptoms you see? I would really like to understand if AltTab is still running or if it crashed.

I tried assigning the same shortcut as the app-switcher, starting/stopping AltTab, sleeping/waking my machine, etc. I also tried binding a global shortcut using System Preferences > Keyboard > Shortcuts after I start AltTab. I wanted to see if maybe the way it works is "last come gets the shortcut". That could explain the issue as the system may sometimes re-grab the global shortcuts for some reason, maybe after a wake, maybe on restart, etc, and that would mean AltTab doesn't respond to it anymore. "Unfortunately", I never got any problems. The shortcut works all the time for me.

Update: another possibility is an interaction with the Accessibility permissions. I say that because if restarting AltTab doesn't fix the issue, it may be that the accessibility permission has some issue. Is the app running after restart, or quitting instantly? Is the checkbox there in the System Preferences > Security & Privacy > Privacy?

@lwouis
Copy link
Owner

lwouis commented Apr 1, 2020

Sharing some research: Kentzo/ShortcutRecorder#114 (comment)

@kungpaogao
Copy link

Yah, I'm having a hard time reproducing the bug within the past few days. I'm honestly not sure what triggered it. It occurred on an older version, but then I updated, and maybe it occurred because I had to reset the Accessibility permissions after the new install (which I now have).

Best case, it just doesn't occur again :)

@stevemartina-salesforce
Copy link
Author

stevemartina-salesforce commented Apr 2, 2020 via email

@lwouis
Copy link
Owner

lwouis commented Apr 3, 2020

@stevemartina-salesforce are you on the latest version now? If not, could you try it, and see if the issue still happens to you? It seems upgrading fixed it for @kungpaogao.

Another thing you could do is check in the System Preferences > Security & Privacy what's listed, and potentially removing/adding back.

@stevemartina-salesforce
Copy link
Author

stevemartina-salesforce commented Apr 3, 2020 via email

@lwouis
Copy link
Owner

lwouis commented May 3, 2020

Hi @stevemartina-salesforce! Do you think we can close this issue now, or have you seen it happen again?

@stevemartina-salesforce
Copy link
Author

stevemartina-salesforce commented May 4, 2020 via email

@lwouis
Copy link
Owner

lwouis commented May 4, 2020

Oh! Dynamically adding/removing keyboards! That's a use-case i haven't explored in depth! It's possible that registering keyboard inputs as we do for the shortcuts is specific to the active keyboard, and that switching to another keyboard means we need to bind again.

I'll experiment locally with keyboard, mouse, and display, being added and removed in the middle of using AltTab. I think that may be the root cause, and could affect also mouse and display. Update: I experimented with mouse, keyboard and displays connecting/disconnecting, and AltTab reacts perfectly to all scenarios.

@lwouis lwouis changed the title 2.3.2 often doesn't fire Keyboard shortcuts sometimes stop being recognized by AltTab May 4, 2020
@lwouis
Copy link
Owner

lwouis commented May 4, 2020

I just tested with my external bluetooth keyboard and connecting/disconnecting it doesn't affect AltTab at all. Interestingly, I can use AltTab with the built-in macbook pro keyboard, or the external bluetooth keyboard, or both at the same time like holding alt on one and tab on the other. This makes me think that there is an OS layer converting keyboards inputs to events, and we subscribe later on the stack at the events level which is independent on physical keyboards used.

To recap, things I have explored without reproducing the issue so far:

  • Going in-and-out of sleep.
  • Settings a shortcut in System Preferences > Keyboard > Shortcuts after AltTab is running. The hypothesis here was that it would take precedence over AltTab's.
  • AltTab crashes and the shortcuts binding is "stuck". I have AltTab crashing very frequently when I develop it, and I could never reproduce the issue.
  • Connecting/Disconnecting external keyboards.
  • Removing the Accessibility permission while AltTab is running.

I'm a bit out of ideas on what could be triggering the issue here. Especially since it persists through AltTab being restarted.

One thing that may help: @stevemartina-salesforce could you please try following the instructions I wrote here? There is a link to a debug build of AltTab which logs keyboard events. You could run that build locally, and when it gets stuck next time, open Console.app, press the shortcut, and share here what is printed.

@mfn
Copy link

mfn commented May 4, 2020

I've also experiences this, rare but it happens.

My unscientific impression was this happened when I was "faster then light" at times switching between windows/apps. Happened also to HyperSwitch countless of times.

I'll pay more attention next times about the details.

@lwouis
Copy link
Owner

lwouis commented May 11, 2020

I re-read this whole thread here, and to be honest I'm not 100% sure that we are all talking about the same issue. The descriptions given are a bit unclear to be honest.

Could you please record using Loom or some other easy to use tool to share video capture of your screen next time a similar issue happens? This way I can review the footage and maybe get a clue at what's happening. Right now I'm pretty much stuck because I have actually never seen it happen, the descriptions are pretty fuzzy as to what the behaviors are, and I tried every step-by-step here to reproduce and it didn't.

@mfn
Copy link

mfn commented May 11, 2020

It always happens in the worst possible time where I can't just stop and and analyze it to deep :-( [i.e. during work]

Last time, CMD-tab was not recognized at all. Even stopping and starting (!) AltTab did not fix it. Eventually after "some time" it suddenly just worked again (same happened to HyperSwitch I was having run in CMD-~). I did not reboot to fix it, it simply "cured" itself.

I know, this is even less then you asked for, sorry!

@lwouis
Copy link
Owner

lwouis commented May 12, 2020

@mfn i'm starting to wonder if this issue is related to AltTab. You say that it affects HyperSwitch as well, and most importantly, that it happens when AltTab is not running. When AltTab is not running, there should not be any interaction with the OS.

I'm thinking that you may have some keyboard disfunction. Are you using an external keyboard, or is it a built-in macbook keyboard perhaps?

On macbooks, there has been lots of talks about defective keyboards for instance. Dust could get stuck behind the keys and prevent them from working properly.

Do you think this could be the issue here? This or another global app (I use Karabiner for instance to remap my keyboard)

@mfn
Copy link

mfn commented May 12, 2020

that it happens when AltTab is not running

Hmm, wait, I didn't say that. Or at least, didn't meant to :)

CMD-tab falls back to its default OSX behaviour, using only the built-in app/window switching capabilities. Sorry if this wasn't clear.

I.e. closing AltTab and starting it again did not immediately fix it. It just happened to work after "some time" again (minutes, not hours).

Are you using an external keyboard, or is it a built-in macbook keyboard perhaps?

External! Connected via USB (2?) via adapter to USB-C

On macbooks, there has been lots of talks about defective keyboards for instance. Dust could get stuck behind the keys and prevent them from working properly.

Ah yes, but the key-press it's working, it's just AltTab (and HyperSwitch) not picking it up 😄

@lwouis
Copy link
Owner

lwouis commented May 12, 2020

@mfn It seems to me that the issue you describe is very different from the OP. We may want to make a new ticket to distinguish these. There may even be more than 3, because some of the descriptions here are a bit hard to visualise.

Now about your specific case, it's pretty mysterious. It may be a macOS issue where the queue of apps listening has some issue that fixes itself after a few minutes? Pretty much impossible to investigate without more data :/

@joeberlin123
Copy link

joeberlin123 commented May 12, 2020

@lwouis First of all, thank for the great app.

I see the same behavior as @mfn

  • most of the time everything works fine
  • At some point Alttab no longer works. When the key combination is pressed, Mac OS reacts with the default behavior of the key combination. This applies to both the internal and external keyboard. For me there is no indication when this will happen.
  • Restart of altab is not fixing the problem.
  • At some point everything works fine again. Again for me no hint what is fixing the problem

lwouis added a commit that referenced this issue May 25, 2020
BREAKING CHANGE: this rework should fix all sorts of issues when OS events happen in parallel: new windows, new apps, user shortcuts, etc. Here are example of use-cases that should work great now, without, and very quickly:

* AltTab is open and an app/window is launched/quit
* A window is minimized/deminimized, and while the animation is playing, the user invokes AltTab
* An app starts and takes a long time to boot (e.g. Gimp)
* An app becomes unresponsive, yet AltTab is unaffected and remains interactive while still processing the state of the window while its parent app finally stops being frozen

closes #348, closes #157, closes #342, closes #93
lwouis added a commit that referenced this issue May 25, 2020
BREAKING CHANGE: this rework should fix all sorts of issues when OS events happen in parallel: new windows, new apps, user shortcuts, etc. Here are example of use-cases that should work great now, without, and very quickly:

* AltTab is open and an app/window is launched/quit
* A window is minimized/deminimized, and while the animation is playing, the user invokes AltTab
* An app starts and takes a long time to boot (e.g. Gimp)
* An app becomes unresponsive, yet AltTab is unaffected and remains interactive while still processing the state of the window while its parent app finally stops being frozen

closes #348, closes #157, closes #342, closes #93
@mfn
Copy link

mfn commented Aug 12, 2020

What version are you on, at the moment?

To the best of my knowledge, I'm on the latest: 10.15.6 (19G73)

Please feel free to update to the latest now

Thanks, done. Wohoo, dark mode icon 😄


I guess it was too late, I didn't realize this was the SecureInput issue despite running the very command; apologies. I guess I was too tired. In my mind I related …loginwindow console to the console.app I was having open 🤷‍♀️

@just-Bri
Copy link

@reifnotreef there is no issue using cmd-tab. Try it out for yourself. Go in AltTab's preferences, and set cmd-tab to any shortcut. It will work.

I have tried several times, with several different apps, and nothing will register the shortcut when assigned. Is there something in OSXs settings I need to change? It's extremely frustrating having different shortcuts between OS's.

@lwouis
Copy link
Owner

lwouis commented Aug 12, 2020

@reifnotreef hard to know what's wrong with your setup without more information. Are you using an external keyboard? Software like Karabiner, Synergy, anything that impacts the keyboard? Could you please see the information in this thread? It may be a similar scenario you're having, where other stuff gets in the way. AltTab itself supports binding to any shortcut. The only exception I know of is if a shortcut is already registered in System Preferences > Keyboard > Shortcuts, which is not the case for cmd+tab. Anyway, many people use AltTab with cmd+tab, so it is indeed possible

@lwouis
Copy link
Owner

lwouis commented Aug 12, 2020

To anyone interested

I've been working on a branch where I rewrote the keyboard handling using another API. It has different pros and cons compared to the current implementation:

Pros:

  • Not affected by Secure Input. It works on password fields, or if some app doesn't turn Secure Input off.

Cons:

  • Can't override cmd+tab. I guess it has lower priority than the previous method. Update: I found a solution with new private APIs. It's working during my local tests.
  • Doesn't work on another thread like the old method can, so things like quick switches are not possible since the UI will not know you released the shortcut until it has displayed the thumbnails view already. So flashing occurs. Here there are probably (heavy) ways to handle that, like having the keyboard monitoring happen on another dedicated process, and exchange through XPC. Exploring XPC could be a gateway to Add CLI support #371 as a side-effect.

I'm not sure what to do now. Should I release this? Maybe I should work on the cons, and figure out some breakthroughs? This stuff is a nightmare to work on btw 🙉

If you're interested, please try out this build and let me know if it works for you. Try it under Secure Input and try it with command+tab. Also be tricky and try all shorts of messy things like modifiers-only shortcuts, etc.

lwouis added a commit that referenced this issue Aug 12, 2020
BREAKING CHANGE: the previous keyboard support implementation was not working if any app on the system activated Secure Input and didn't turn it off. This is a major hurdle for most global shortcut apps. This update introduces a new implementation which is unaffected by Secure Input. AltTab shortcuts should now work reliably
@stidch
Copy link

stidch commented Aug 13, 2020

If you're interested, please try out this build and let me know if it works for you. Try it under Secure Input and try it with command+tab. Also be tricky and try all shorts of messy things like modifiers-only shortcuts, etc.

Working with this build the whole day without any problems so far. Usually AltTab stopped working because Secure Input quite soon. I'm using it with command+tab.

@caduellery
Copy link

2 things I use are not working well in this version:

  • Fast switching with apparition delay of 100ms (had to set to 0ms and get a glitch)
  • The use of Cmd+Shift+Tab to select previous window is bringing the default MacOS switcher in front of AltTab.

@lwouis
Copy link
Owner

lwouis commented Aug 14, 2020

Fast switching with apparition delay of 100ms (had to set to 0ms and get a glitch)

What do you mean? I don't get it. Maybe share a video to help visualize the issue?

Edit: I was able to reproduce! This is another consequence of keyboard input being back on the main thread. That's unfortunate. I'll see if I can mitigate this

The use of Cmd+Shift+Tab to select previous window is bringing the default MacOS switcher in front of AltTab.

Oh! I'll look into that. I'm using a private API to specifically disable the native switcher if the user sets the main shortcut to cmd-tab. I forgot about the shift shortcut!

Edit: Ok I fixed that issue

lwouis added a commit that referenced this issue Aug 14, 2020
BREAKING CHANGE: the previous keyboard support implementation was not working if any app on the system activated Secure Input and didn't turn it off. This is a major hurdle for most global shortcut apps. This update introduces a new implementation which is unaffected by Secure Input. AltTab shortcuts should now work reliably
lwouis added a commit that referenced this issue Aug 14, 2020
BREAKING CHANGE: the previous keyboard support implementation was not working if any app on the system activated Secure Input and didn't turn it off. This is a major hurdle for most global shortcut apps. This update introduces a new implementation which is unaffected by Secure Input. AltTab shortcuts should now work reliably
@lwouis
Copy link
Owner

lwouis commented Aug 14, 2020

Here is a new build where I fixed both issues. I'll be on vacations for 9 days. Please everyone who can, take that time to test this build: AltTab.app.zip

The code is a mess, and I need to reorganize this so it's more approachable, but from my tests, it's looking good. The complexity of keyboard shortcuts being so customizable and combinations of preferences make it really hard to be confident though. That's why I need help with QA 👍

lwouis added a commit that referenced this issue Aug 14, 2020
BREAKING CHANGE: the previous keyboard support implementation was not working if any app on the system activated Secure Input and didn't turn it off. This is a major hurdle for most global shortcut apps. This update introduces a new implementation which is unaffected by Secure Input. AltTab shortcuts should now work reliably
lwouis added a commit that referenced this issue Aug 14, 2020
BREAKING CHANGE: the previous keyboard support implementation was not working if any app on the system activated Secure Input and didn't turn it off. This is a major hurdle for most global shortcut apps. This update introduces a new implementation which is unaffected by Secure Input. AltTab shortcuts should now work reliably
@caduellery
Copy link

Tested here and both fixes are OK, thanks!
Found a new one: on the old version we can just hold Cmd+Tab pressed to cycle fast between windows thumbnails. Now holding the keys simply does nothing (seems like the "repeat" behavior of holding a key is disabled).

@caduellery
Copy link

Another one: when Alt+Tabbing the AltTab Preferences window is not showing itself in the list.

@ghost
Copy link

ghost commented Aug 16, 2020

OK, I'll start using this test build from now until whenever to see if the problem remains or not!

@zzamboni
Copy link

I've also noticed that the AltTab preferences window does not show up in the switcher when using the test version.

Another change: with this version, Cmd-Shift-Tab no longer pops up the regular macOS application switcher as before (I had been using this as a workaround when I wanted to switch by apps).

@lwouis lwouis closed this as completed in d3253ba Aug 18, 2020
lwouis pushed a commit that referenced this issue Aug 18, 2020
# [5.0.0](v4.19.0...v5.0.0) (2020-08-18)

### Bug Fixes

* app icon was not showing on macos 10.12 (see [#522](#522)) ([2a45dec](2a45dec))
* battle.net installer and wow were not showing in alt-tab ([793b10b](793b10b)), closes [#536](#536)
* portuguese from portugal was shown to brazil users ([e54c2de](e54c2de))
* rare crash when the os was not providing the current space id ([cf05044](cf05044))
* rewrote the preference window to fix crashes and jank (closes [#502](#502)) ([f9f5b8a](f9f5b8a))

### Features

* change default key to select window from `return` to `space` ([eec694e](eec694e))
* complete rewrite of the keyboard support (closes [#157](#157)) ([d3253ba](d3253ba))
* show notification badges on top of app icons (closes [#523](#523)) ([fb62834](fb62834))
* update portuguese (brazil) localization ([726acd3](726acd3))
* updated japanese localization ([36c7b0a](36c7b0a))

### BREAKING CHANGES

* the previous keyboard support implementation was not working if any app on the system activated Secure Input and didn't turn it off. This is a major hurdle for most global shortcut apps. This update introduces a new implementation which is unaffected by Secure Input. AltTab shortcuts should now work reliably
@ghost
Copy link

ghost commented Aug 23, 2020

Here is a new build where I fixed both issues. I'll be on vacations for 9 days. Please everyone who can, take that time to test this build: AltTab.app.zip

The code is a mess, and I need to reorganize this so it's more approachable, but from my tests, it's looking good. The complexity of keyboard shortcuts being so customizable and combinations of preferences make it really hard to be confident though. That's why I need help with QA 👍

Should we continue testing, or go back to main build? I'm still on this test build and seems to fix it, because I've forgotten about the bug completely. :)

@lwouis
Copy link
Owner

lwouis commented Aug 23, 2020

@mindfulsource I waited a bit, then as everyone reported good results, I merged the PR and closed this ticket. You can go back to the main/public release now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need breakthrough Need a breakthrough idea to move forwards unreproducible Need help from the author to reproduce the issue
Projects
None yet
Development

No branches or pull requests