Interference with Cmd-Tab ⌘⭾ events when a Secure Input app is running

Describe the bug

I've noticed that when -ing to an app with Secure Input enabled (in this case iTerm) and BTT running (even though not a single shortcut in BTT is active; and touchpad bindings don't include ) the app switcher functionality bugs:

  • The official app switcher still works, but it takes a short, but noticeable delay to switch
  • The greater AltTab replacement doesn't work properly: the switcher windows stays opened even though all the keys are depressed

Please check the attached video for a very clean reproduction with a single clean keybind (↓, tap(↓↑), ↑), so we see all key events are registered properly). Bug starts at the 1st second after I've reset the previous key events:

  • On the ←left in this video is iTerm with Secure Input enabled
  • On the →right is Karabiner EventViewer, which shows all the key events
    (the bug starts at the 1st second after I've reset the previous key events)

Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):

Keyboard (though, just to repeat, no keybindings are registered with BTT; and none of the trackpad gestures use )

Screenshots

See the video above

Device information:

  • Type of Mac: MBP late 2012
  • macOS version: 10.15
  • BetterTouchTool version: 3.974

Additional information (e.g. StackTraces, related issues, screenshots, workarounds, etc.):

Tried to disable all keybinds and all trackpad gestures with , but that didn't help, I guess BTT still registers some kbd hook or something, which introduces this bug in specific conditions

Priority helper tool is active

And an illustration of the delay with the official switcher based on the attached video frame timestamps:

  • with BTT 0.4s = 2.049s − 1.649s
  • no BTT 0.083s = 4.050s − 3.967s

with BTT

no BTT

AltTab seems to work fine here with SecureInput and BTT, so maybe it's some specific setting.
Do you have any key sequences configured in BTT?

No, all keyboard shortcuts/key sequences are disabled (greyed out).
(also, priority helper tool is active)

Let me try with deleting the settings and starting with a blank profile
Seems there is no full export function, so is it correct that if I quit BTT, rename ~/Library/Application Support/BetterTouchTool folder and start BTT, it'll start with a clean profile, but then I'll be able to just as easily rename this folder back (so I won't lose anything)?
(sync is disabled)

Also, this doesn't happen literally every time, but at the same time in this test with just 2 apps (so mouse switch back to EventViewer, keyboard switch forth to the terminal), it bugs pretty reliably, every ~3rd-4th back&forth switch bugs on the viewer→terminal keyboard (also happend on the 1st)
And if I disable Secure Keyboard Entry in iTerm, then I can't repro it anymore

This seems to be the case as I can't reproduce it with a clean profile, so will hunt down that setting, maybe something is not disabled properly

By the way, while trying to find the keybind at issue, I've noticed that when I keep BTT settings window opened (to move keybinds from the default active profile to the disabled one), sometimes when this bug is triggered, the settings windows disappears, so the app simply crashes (the menu icon also disappears)

In that case, maybe check whether there is a crashlog in the macOS console app under "Crash Reports". Possibly it contains some hint on what causes this

So I've opened console log for BTT process and noticed that it it has some errors right away before I do any tests (see the first few lines with MacOS error: -25304 and UNIX error exception: 17), and then the crash happens around the →crash? marker (that's the ⌘⭾ test)

(I can't attach text files here, can I?)

default	19:17:11.521228+0700	                  	BetterTouchTool   	BetterTouchTool	key windwo (null) (null)
default	19:17:16.145598+0700	security_exception	Security          	BetterTouchTool	UNIX error exception: 17
default	19:17:16.906850+0700	security_exception	Security          	BetterTouchTool	MacOS error: -25304
default	19:17:16.948954+0700	security_exception	Security          	BetterTouchTool	MacOS error: -25304
default	19:17:21.325356+0700	                  	BetterTouchTool   	BetterTouchTool	key windwo (null) (null)
default	19:17:27.142205+0700	security_exception	Security          	BetterTouchTool	UNIX error exception: 17
default	19:17:27.851497+0700	security_exception	Security          	BetterTouchTool	MacOS error: -25304
→crash?	19:17:33.417365+0700	front-35286506    	HIServices        	BetterTouchTool	SetFrontProcess: asn=0x0-0x15c15c options=1
default	19:17:34.338119+0700	front-35286506    	HIServices        	BetterTouchTool	FRONTLOGGING: version 1
default	19:17:34.338159+0700	front-35286506    	HIServices        	BetterTouchTool	Registering, pid=10578
default	19:17:34.356456+0700	front-35286506    	LaunchServices    	BetterTouchTool	CHECKIN: pid=10578
default	19:17:34.707933+0700	front-35286506    	LaunchServices    	BetterTouchTool	CHECKEDIN: pid=10578 asn=0x0-0x163163 foreground=0
default	19:17:35.135255+0700	front-35286506    	HIServices        	BetterTouchTool	Registered, pid=10578 ASN=0x0,0x163163
default	19:17:35.135734+0700	front-35286506    	HIServices        	BetterTouchTool	Registered, pid=10578 cgConnectionID=6c213
default	19:17:35.143938+0700	front-35286506    	HIServices        	BetterTouchTool	BringForward: pid=10578 asn=0x0-0x163163 bringForward=0 foreground=0 uiElement=1 launchedByLS=1 modifiersCount=1 allDisabled=0
default	19:17:35.144063+0700	front-35286506    	HIServices        	BetterTouchTool	BringFrontModifier: pid=10578 asn=0x0-0x163163 Modifier 0 hideAfter=0 hideOthers=0 dontMakeFrontmost=1 mouseDown=0/0 seed=0/0
default	19:17:35.146241+0700	Appearance        	AppKit            	BetterTouchTool	Current system appearance, (HLTB: 1), (SLS: 0)
default	19:17:35.154522+0700	Appearance        	AppKit            	BetterTouchTool	Post-registration system appearance: (HLTB: 1)
default	19:17:35.233239+0700	security_exception	Security          	BetterTouchTool	UNIX error exception: 17
default	19:17:35.274322+0700	Default           	XCTTargetBootstrap	BetterTouchTool	Registering for test daemon availability notify post.
default	19:17:35.275609+0700	Default           	XCTTargetBootstrap	BetterTouchTool	notify_get_state check indicated test daemon not ready.
default	19:17:35.287044+0700	                  	AppKit            	BetterTouchTool	NSDocumentController Info.plist warning: The values of CFBundleTypeRole entries must be 'Editor', 'Viewer', 'None', or 'Shell'.
default	19:17:35.305095+0700	Appearance        	AppKit            	BetterTouchTool	NSApp cache appearance:
-NSRequiresAquaSystemAppearance: 0
-appearance: (null)
-effectiveAppearance: <NSCompositeAppearance: 0x600002e12c00
 (
    "<NSAquaAppearance: 0x600002e12a80>",
    "<NSSystemAppearance: 0x600002e12580>"
)>
default	19:17:35.358023+0700	front-35286506	HIServices	BetterTouchTool	SignalReady: pid=10578 asn=0x0-0x163163
default	19:17:35.373374+0700	front-35286506	LaunchServices	BetterTouchTool	SIGNAL: pid=10578 asn=0x0x-0x1454435
default	19:17:35.581618+0700		libDiagnosticMessagesClient.dylib	BetterTouchTool	MessageTracer: Falling back to default whitelist
default	19:17:35.605294+0700	client	CoreAnalytics	BetterTouchTool	Received configuration update from daemon (initial)
default	19:17:35.717214+0700		BetterTouchTool	BetterTouchTool	0 elapsed 0.293928
default	19:17:35.833755+0700		BetterTouchTool	BetterTouchTool	1 elapsed 0.410473
default	19:17:35.834091+0700		BetterTouchTool	BetterTouchTool	2 elapsed 0.410813
default	19:17:35.834382+0700		BetterTouchTool	BetterTouchTool	3 elapsed 0.411103
default	19:17:35.834582+0700		BetterTouchTool	BetterTouchTool	4 elapsed 0.411302
default	19:17:35.837402+0700		BetterTouchTool	BetterTouchTool	5 elapsed 0.414119
default	19:17:35.837799+0700		BetterTouchProcessPrioWatcher	BetterTouchProcessPrioWatcher	BTT did launch
default	19:17:35.837893+0700		BetterTouchTool	BetterTouchTool	6 elapsed 0.414616
default	19:17:35.844592+0700		BetterTouchProcessPrioWatcher	BetterTouchProcessPrioWatcher	checking signature for bundle: file:///Applications/5%20Util/6%20Key&Mouse/BetterTouchTool.app/
default	19:17:35.917298+0700		BetterTouchTool	BetterTouchTool	Hyper key used 0
error	19:17:36.623903+0700	default	IOHIDLib	BetterTouchTool	IOConnectCallMethod(kIOHIDLibUserClientOpen):e00002c5
default	19:17:36.669837+0700		BetterTouchTool	BetterTouchTool	7 elapsed 1.246551
default	19:17:36.676920+0700		BetterTouchTool	BetterTouchTool	8 elapsed 1.253636
default	19:17:36.677680+0700		BetterTouchTool	BetterTouchTool	9 elapsed 1.254399
default	19:17:36.678117+0700		BetterTouchTool	BetterTouchTool	10 elapsed 1.254837
default	19:17:36.687701+0700		BetterTouchTool	BetterTouchTool	11 elapsed 1.264421
default	19:17:36.707506+0700		BetterTouchTool	BetterTouchTool	12 elapsed 1.284222
default	19:17:36.707760+0700		BetterTouchTool	BetterTouchTool	13 elapsed 1.284384
default	19:17:36.708062+0700		BetterTouchTool	BetterTouchTool	14 elapsed 1.284786
default	19:17:36.712903+0700		BetterTouchTool	BetterTouchTool	15 elapsed 1.289624
default	19:17:36.725513+0700		BetterTouchTool	BetterTouchTool	16 elapsed 1.302234
default	19:17:36.725687+0700		BetterTouchTool	BetterTouchTool	17 elapsed 1.302410
default	19:17:36.739300+0700		BetterTouchTool	BetterTouchTool	18 elapsed 1.316021
default	19:17:36.739434+0700		BetterTouchTool	BetterTouchTool	19 elapsed 1.316156
default	19:17:36.740010+0700		BetterTouchTool	BetterTouchTool	20 elapsed 1.316732
default	19:17:36.740292+0700		BetterTouchTool	BetterTouchTool	21 elapsed 1.317016
default	19:17:36.740453+0700		BetterTouchTool	BetterTouchTool	22 elapsed 1.317177
default	19:17:36.743163+0700		BetterTouchTool	BetterTouchTool	23 elapsed 1.319882
default	19:17:36.743499+0700		BetterTouchTool	BetterTouchTool	24 elapsed 1.320221
default	19:17:36.750624+0700	SOConfigurationClient	AppSSOCore	BetterTouchTool	-[SOConfigurationClient init]  on <private>
default	19:17:36.751204+0700	SOServiceConnection	AppSSOCore	BetterTouchTool	<SOServiceConnection: 0x600000046f00>: new XPC connection
default	19:17:36.751213+0700		BetterTouchTool	BetterTouchTool	25 elapsed 1.327927
default	19:17:36.755597+0700		BetterTouchTool	BetterTouchTool	26 elapsed 1.332316
default	19:17:36.759999+0700		CFNetwork	BetterTouchTool	Faulting in NSHTTPCookieStorage singleton
default	19:17:36.760035+0700		CFNetwork	BetterTouchTool	Faulting in CFHTTPCookieStorage singleton
default	19:17:36.760065+0700		CFNetwork	BetterTouchTool	Creating default cookie storage with process/bundle identifier
default	19:17:36.761918+0700	ATS	CFNetwork	BetterTouchTool	Task <4C3858D2-3D20-4087-85E1-13E18BE1D133>.<0> {strength 0, tls 4, ct 0, sub 0, sig 1, ciphers 0, bundle 0, builtin 0}
default	19:17:36.767091+0700		CFNetwork	BetterTouchTool	Connection 1: enabling TLS
default	19:17:36.767128+0700		CFNetwork	BetterTouchTool	Connection 1: starting, TC(0x0)
default	19:17:36.767201+0700		libnetwork.dylib	BetterTouchTool	[C1 28271B11-4F77-440E-BAE3-DEF1DB39C66F Hostname#1b7d7e6c:443 tcp, url hash: 6c43685c, tls] start
default	19:17:36.767868+0700		libnetwork.dylib	BetterTouchTool	nw_connection_report_state_with_handler_on_nw_queue [C1] reporting state preparing
default	19:17:36.769395+0700		CFNetwork	BetterTouchTool	Task <4C3858D2-3D20-4087-85E1-13E18BE1D133>.<0> setting up Connection 1
error	19:17:36.790061+0700		libnetwork.dylib	BetterTouchTool	nw_socket_connect [C1.1:3] connectx(15 (guarded), [srcif=0, srcaddr=<private>, dstaddr=<private>], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [64: Host is down]
error	19:17:36.791100+0700		libnetwork.dylib	BetterTouchTool	nw_socket_connect <private> connectx failed (fd 15) [64: Host is down]
error	19:17:36.791138+0700		libnetwork.dylib	BetterTouchTool	nw_socket_connect connectx failed [64: Host is down]
default	19:17:36.791177+0700	BoringSSL	libboringssl.dylib	BetterTouchTool	nw_protocol_boringssl_error(1679) [0x7fd8834267a0] Lower protocol stack error pre TLS handshake: 64
default	19:17:36.792795+0700	BoringSSL	libboringssl.dylib	BetterTouchTool	nw_protocol_boringssl_remove_input_handler(1012) [0x7fd8834267a0] nw_protocol_boringssl_remove_input_handler forced true
default	19:17:36.792843+0700	BoringSSL	libboringssl.dylib	BetterTouchTool	nw_protocol_boringssl_remove_input_handler(1030) [0x7fd8834267a0] Transferring nw_protocol_boringssl_t handle back into ARC for autorelease
default	19:17:36.795650+0700		libnetwork.dylib	BetterTouchTool	nw_connection_report_state_with_handler_on_nw_queue [C1] reporting state failed error Host is down
error	19:17:36.795876+0700		CFNetwork	BetterTouchTool	Connection 1: received failure notification
error	19:17:36.795942+0700		CFNetwork	BetterTouchTool	Connection 1: failed to connect 1:64, reason -1
error	19:17:36.795973+0700		CFNetwork	BetterTouchTool	Connection 1: encountered error(1:64)
default	19:17:36.795999+0700		CFNetwork	BetterTouchTool	Connection 1: is being canceled
default	19:17:36.796050+0700	Summary	CFNetwork	BetterTouchTool	Connection 1: summary for unused connection {protocol="(null)", domain_lookup_duration_ms=0, connect_duration_ms=0, secure_connection_duration_ms=0, idle_duration_ms=0}
default	19:17:36.796396+0700		libnetwork.dylib	BetterTouchTool	[C1 28271B11-4F77-440E-BAE3-DEF1DB39C66F Hostname#1b7d7e6c:443 tcp, url hash: 6c43685c, tls] cancel
default	19:17:36.796447+0700		libnetwork.dylib	BetterTouchTool	[C1 Hostname#1b7d7e6c:443 tcp, url hash: 6c43685c, tls] cancelled
default	19:17:36.797404+0700		libnetwork.dylib	BetterTouchTool	0.000s [C1 5A8EE63D-EA88-4A4F-8804-6E892B92E6B7 Hostname#1b7d7e6c:443 resolver path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] path:start
default	19:17:36.797455+0700		libnetwork.dylib	BetterTouchTool	0.000s [C1 5A8EE63D-EA88-4A4F-8804-6E892B92E6B7 Hostname#1b7d7e6c:443 resolver path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] path:satisfied
default	19:17:36.797501+0700		libnetwork.dylib	BetterTouchTool	0.000s [C1 5A8EE63D-EA88-4A4F-8804-6E892B92E6B7 Hostname#1b7d7e6c:443 resolver path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] resolver:start_dns
default	19:17:36.798422+0700		libnetwork.dylib	BetterTouchTool	0.005s [C1 5A8EE63D-EA88-4A4F-8804-6E892B92E6B7 Hostname#1b7d7e6c:443 resolver path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] resolver:receive_dns
default	19:17:36.798594+0700		libnetwork.dylib	BetterTouchTool	0.005s [C1.1 36C06B39-8575-4EBF-971A-87413DEF4EE0 IPv4#14aa8dcc:443 socket-flow path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] path:start
default	19:17:36.798732+0700		libnetwork.dylib	BetterTouchTool	0.005s [C1.1 36C06B39-8575-4EBF-971A-87413DEF4EE0 IPv4#14aa8dcc:443 socket-flow path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] path:satisfied
default	19:17:36.798787+0700		libnetwork.dylib	BetterTouchTool	0.006s [C1.1 36C06B39-8575-4EBF-971A-87413DEF4EE0 IPv4#14aa8dcc:443 socket-flow path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] flow:start_connect
default	19:17:36.798933+0700		libnetwork.dylib	BetterTouchTool	0.026s [C1.1 36C06B39-8575-4EBF-971A-87413DEF4EE0 IPv4#14aa8dcc:443 socket-flow path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] flow:failed_connect Host is down
default	19:17:36.798990+0700		libnetwork.dylib	BetterTouchTool	0.027s [C1 5A8EE63D-EA88-4A4F-8804-6E892B92E6B7 Hostname#1b7d7e6c:443 resolver path=satisfied (Path is satisfied), interface: utun2, ipv4, dns] resolver:children_failed
default	19:17:36.799025+0700		libnetwork.dylib	BetterTouchTool	0.029s [C1] path:cancel
default	19:17:36.800029+0700		libnetwork.dylib	BetterTouchTool	nw_connection_report_state_with_handler_on_nw_queue [C1] reporting state cancelled error Host is down
default	19:17:36.820127+0700		BetterTouchTool	BetterTouchTool	27 elapsed 1.396845
default	19:17:36.835866+0700		CFNetwork	BetterTouchTool	Task <4C3858D2-3D20-4087-85E1-13E18BE1D133>.<0> can retry(N) with reason(2) for error [1:64]
error	19:17:36.835901+0700		CFNetwork	BetterTouchTool	Task <4C3858D2-3D20-4087-85E1-13E18BE1D133>.<0> HTTP load failed, 0/0 bytes (error code: -1004 [1:64])
error	19:17:36.836201+0700		CFNetwork	BetterTouchTool	NSURLConnection finished with error - code -1004
default	19:17:36.836447+0700	Summary	CFNetwork	BetterTouchTool	Task <4C3858D2-3D20-4087-85E1-13E18BE1D133>.<0> summary for task failure {transaction_duration_ms=77, response_status=0, connection=1, reused=1, request_start_ms=0, request_duration_ms=0, response_start_ms=0, response_duration_ms=0, request_bytes=0, response_bytes=0, cache_hit=0}
default	19:17:36.846649+0700		BetterTouchTool	BetterTouchTool	menubar height 22.000000
default	19:17:37.479372+0700		BetterTouchTool	BetterTouchTool	28 elapsed 2.056092
default	19:17:37.479568+0700		BetterTouchTool	BetterTouchTool	29 elapsed 2.056290
default	19:17:37.479732+0700		BetterTouchTool	BetterTouchTool	30 elapsed 2.056456
default	19:17:37.479844+0700		BetterTouchTool	BetterTouchTool	31 elapsed 2.056567
default	19:17:37.481069+0700		BetterTouchTool	BetterTouchTool	32 elapsed 2.057783
default	19:17:37.490000+0700	security_exception	Security	BetterTouchTool	MacOS error: -67052
default	19:17:37.501075+0700		BetterTouchTool	BetterTouchTool	33 elapsed 2.077789
default	19:17:37.504748+0700		BetterTouchTool	BetterTouchTool	34 elapsed 2.081462
default	19:17:37.505834+0700		BetterTouchTool	BetterTouchTool	35 elapsed 2.082554
default	19:17:37.515789+0700		libnetwork.dylib	BetterTouchTool	nw_path_evaluator_start [FDFFA651-0588-4758-8EAA-D885CFFAE6EB <NULL> generic, indefinite]
	path: satisfied (Path is satisfied), interface: utun2, ipv4, dns
default	19:17:37.516299+0700		BetterTouchTool	BetterTouchTool	36 elapsed 2.093018
default	19:17:37.522768+0700		BetterTouchTool	BetterTouchTool	37 elapsed 2.099487
default	19:17:37.523422+0700		BetterTouchTool	BetterTouchTool	38 elapsed 2.100144
default	19:17:37.526112+0700		BetterTouchTool	BetterTouchTool	39 elapsed 2.102830
default	19:17:37.526984+0700		BetterTouchTool	BetterTouchTool	40 elapsed 2.103704
default	19:17:37.527384+0700	Connections	UserNotifications	BetterTouchTool	[com.hegenberg.BetterTouchTool] Requesting authorization with options 7
default	19:17:37.542212+0700	security_exception	Security	BetterTouchTool	UNIX error exception: 17
default	19:17:37.722872+0700	Connections	UserNotifications	BetterTouchTool	[com.hegenberg.BetterTouchTool] Requested authorization [ didGrant: 1 hasError: 0 hasCompletionHandler: 1 ]
error	19:17:38.450278+0700	default	IOHIDLib	BetterTouchTool	IOConnectCallMethod(kIOHIDLibUserClientOpen):e00002c5
error	19:17:39.490529+0700	default	IOHIDLib	BetterTouchTool	IOConnectCallMethod(kIOHIDLibUserClientOpen):e00002c5
error	19:17:40.501143+0700	default	IOHIDLib	BetterTouchTool	IOConnectCallMethod(kIOHIDLibUserClientOpen):e00002c5

These are just some system logs that should not be related, if BTT quits there should be a crash log (in the side bar in the console app select "Crash Reports")

And that happens with just a single keybind (moved all others into an inactive profile, key sequences are completely blank)
Though I've noticed that the hidden marker (crossed eye icon) doesn't persist, though the keybind is greyed out (might be hard to see due to the blue highlight)

I already have, it's empty, there were no BTT logs, and I've cleaned everything not to miss one, invoked the crash and still got nothing

But I've noticed a few com.apple.xpc.launchd[1] (com.hegenberg.BTTRelaunch.4824[11104]): Service exited due to SIGTERM | sent by BetterTouchTool[11111] in the system.log reports tab at the time of a crash

ok, the testing didn't seem to resolve anything, so tried again with a blank profile (quit BTT, renamed the app support folder, started BTT), and lo and behold — I could trigger the bug (though again, BTT doesn't seem to quit anymore)
So not sure what else to do

Have you tried exactly the same test on your machine:
I think the trick is to do it quickly and it seems that it requires a trackpad-tap on the EventViewer window before invoking the keybind, with a clean profile I don't seem to be able to invoke the bug without a trackpad tap, but with a tap it happens almost every single time

Just tried again, but still unable to reproduce here.

Maybe try to uninstall the Process Priority Helper - that should not be necessary on current macOS versions anymore:

Sounds stupid, but have you tried to restart your system?

Disabled, restarted, still bugs with a new empty profile :frowning:
(though for a minute there couldn't repro it, but then once it happened, can also repro it reliably, though need to be fast with a click, then ⌘⭾)

(but at least BTT now appears in the AltTab switcher, likely due to the process being unpriviledged anymore :tada:)

I've updated to macOS 13 Ventura and BTT 4.163 hoping this could automagically resolve, but unfortunately this issue still persists :frowning:

Do you have any other idea re. what could be wrong here?