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 inputs are ignored despite all OS permissions being granted #284

Closed
alt-tab-macos-bot opened this issue Apr 28, 2020 · 7 comments
Closed
Labels
bug Something isn't working unreproducible Need help from the author to reproduce the issue

Comments

@alt-tab-macos-bot
Copy link

This issue was opened by a bot after a user submitted feedback through the in-app form.

From: m.terzic@gmail.com

Message:

Hi,

it stopped working a few versions ago. It does not pick "Option" + "tab" at all anymore. It behaves as "tab" was pressed. Tried reinstalling, still the same. Latest Mojave. Are there any new permissions taht are needed?

Debug profile

  • App version: 3.17.0
  • App preferences:
    • NSWindow Frame SUUpdateAlert: 650 498 620 392 0 0 1920 1057
    • NSWindow Frame com.sindresorhus.Preferences.FrameAutosaveName: 685 305 549 502 0 0 1920 1057
    • SUHasLaunchedBefore: 1
    • SULastCheckTime: 2020-04-28 07:34:05 +0000
    • SUUpdateGroupIdentifier: 2568737879
    • SUUpdateRelaunchingMarker: 0
    • alignThumbnails: 1
    • arrowKeysEnabled: true
    • cancelShortcut: ⎋
    • closeWindowShortcut: W
    • hideShowAppShortcut: H
    • holdShortcut: ⌥
    • maxScreenUsage: 85
    • minCellsPerRow: 5
    • minDeminWindowShortcut: M
    • nextWindowShortcut: ⇥
    • preferencesVersion: 3.17.0
    • previousWindowShortcut: ⇧⇥
    • quitAppShortcut: Q
    • theme: 0
  • Applications count: 44
  • Windows: 9
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
    • {isMinimized: false, isHidden: false, isOnAllSpaces: false, spaceId: 1, spaceIndex: 1}
  • OS version: Version 10.15.4 (Build 19E287)
  • OS architecture: x86_64
  • Locale: en_RS (current)
  • Spaces count: 2
  • Dark mode: Dark
  • "Displays have separate Spaces": checked
  • Hardware model: MacBookPro15,1
  • Screens count: 2
    • (0.0, 0.0, 1920.0, 1080.0)
    • (1920.0, 180.0, 1440.0, 900.0)
  • CPU model: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  • Memory size: 34,36 GB
  • Active CPU count: 12
  • Current CPU frequency: 2.6 Ghz
  • Resource utilization:
    • CPU: 0.7%
    • Memory: 46M
    • Threads count: 9

@lwouis lwouis added bug Something isn't working unreproducible Need help from the author to reproduce the issue labels Apr 28, 2020
@lwouis
Copy link
Owner

lwouis commented Apr 28, 2020

I replied to the author:

You said "latest mojave" but the debug profile attached says you are on 10.15.4 which is Catalina. In Catalina Apple added a new permission indeed to display screenshots. You have to add it in System Preferences > Security & Privacy > Privacy > Screen Recording. Also check that the one in Accessibility is correctly checked. Maybe uncheck them and recheck them if you want to be sure.

What exactly happens? The app start properly (can you see its icon in the menubar)? Can you access the preferences from the menubar icon? The when you press the shortcut, what happens on screen?

@HelloAstroWolf
Copy link

Hi, sorry for the naming latest macos incorrectly, its Catalina. I have latest Catalina. And AltTab was working after I got the latest macos update for a few AltTab updates, then it stopped. It has both needed permissions. I tried checking and unchecking them and restarting AltTab. It starts properly, I can open it from menubar icon and access preferences. When preferences windows in open, and I try option+tab, it just behaves as tab, it goes to next option on preferences window. It does not pick option+tab key combination no more. When I click "show" the windows selection appears but it looks like it does not pick keyboard in any way. Command+tab does not work, nor do arrows or tab button (it does not switch between apps or selects them via keyboard, only mouse works). Pressing tab or arrow keys, takes effect on the app behind open AltTAb, somehow AltTab does not gain keyboard input. Macos's useless command+tab still works :)

@lwouis
Copy link
Owner

lwouis commented Apr 29, 2020

When the app boots, it checks permissions. The check is pretty clear and has never bugged for anyone. Also you clicked "Show" and saw the working UI, and even can interact with the mouse. So you have both the Accessibility permission needed to: intercept keyboard inputs + read windows events + focus/minimize/etc windows; and the Screen Recording permission needed to: get screenshots of windows.

Now despite having permissions, the keyboard inputs are not intercepted. I'm afraid I don't see where to go from here. I see only 2 explanations:

  1. The event tap failed to be created:

https://github.com/lwouis/alt-tab-macos/blob/master/src/logic/events/KeyboardEvents.swift#L16

Never happened before. Why would that fail with the permission granted?

  1. The events are intercepted by pass through the matching and are forwarded to the app behind AltTab:

https://github.com/lwouis/alt-tab-macos/blob/master/src/logic/events/KeyboardEvents.swift#L46

Again I don't see how that would be happening.

I made a special build that logs every line in that function:

private func keyboardHandler(proxy: CGEventTapProxy, type: CGEventType, cgEvent: CGEvent, userInfo: UnsafeMutableRawPointer?) -> Unmanaged<CGEvent>? {
    os_log("keyboardHandler1")
    if type == .keyDown || type == .keyUp || type == .flagsChanged {
        os_log("keyboardHandler2")
        if let event_ = NSEvent(cgEvent: cgEvent),
           // workaround: NSEvent.characters is not safe outside of the main thread; this is not documented by Apple
                // see https://github.com/Kentzo/ShortcutRecorder/issues/114#issuecomment-606465340
           let event = NSEvent.keyEvent(with: event_.type, location: event_.locationInWindow, modifierFlags: event_.modifierFlags,
                   timestamp: event_.timestamp, windowNumber: event_.windowNumber, context: nil, characters: "",
                   charactersIgnoringModifiers: "", isARepeat: type == .flagsChanged ? false : event_.isARepeat, keyCode: event_.keyCode) {
            os_log("keyboardHandler3")
            let appWasBeingUsed = App.app.appIsBeingUsed
            os_log("keyboardHandler4")
            App.shortcutMonitor.handle(event, withTarget: nil)
            os_log("keyboardHandler5")
            if appWasBeingUsed || App.app.appIsBeingUsed {
                return nil // focused app won't receive the event
            }
        }
    } else if type == .tapDisabledByUserInput || type == .tapDisabledByTimeout {
        os_log("keyboardHandler6")
        CGEvent.tapEnable(tap: eventTap!, enable: true)
    }
    os_log("keyboardHandler7")
    return Unmanaged.passRetained(cgEvent) // focused app will receive the event
}

Could you please open Console.app, search AltTab in the top right search field, and run that build? Then could you please press a normal key like e, then the shortcut alt-tab, and share what's printed in the Console?

@lwouis lwouis changed the title [In-app feedback] Keyboard inputs are ignored despite all OS permissions being granted Apr 29, 2020
@HelloAstroWolf
Copy link

image
This is what I see in console on option+tab

pressing only one key, like e or backspace, prints nothing.

@lwouis
Copy link
Owner

lwouis commented Apr 30, 2020

@HelloAstroWolf that's all there is, really? I'm surprised :o

It should print when you hit normal keys, and when you hit alt-tab it should print more because it's: alt-down > tab-down > tab-up > alt-up. Each would print some lines.

Here it looks like only the alt-down > tab-downsequence prints stuff, and it prints keyboardHandler7 which means appWasBeingUsed || App.app.appIsBeingUsed was false. Which is very strange

@HelloAstroWolf
Copy link

Removed all permissions. Uninstalled it using brew. Restart. Installed using brew. Works. Looks like macos needs frequent restarts?

@lwouis
Copy link
Owner

lwouis commented May 2, 2020

@HelloAstroWolf that looks like a bug in macOS. I noticed bug during recent work on #127 where I would remove permissions while AltTab is open, and it would still be able to work. It was not always happening, so inconsistent as well.

These permissions are a very low-quality work from Apple. See links I shared in #127 to see the kind of poor consideration they put into the APIs, and the bad consequence on end-user UX.

I'll close this ticket as I think the issue was on macOS side

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

No branches or pull requests

3 participants