-
Notifications
You must be signed in to change notification settings - Fork 114
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
Modifier-only shortcut #114
Comments
AFAIK Cocoa's controls ( I think that's a reasonable request though. |
I wonder what should be the correct value of One option is to change Would that work well for Swift though? Having an optional seems like a better approach. In other hand, majority of the users will probably keep this feature off (it will definitely be off by default). Forcing developers to unwrap the value is not good. I need to take a look at how Apple's frameworks address this problem. |
Probably a better approach is to change the type to a UInt32 enum and use its maximum as None. |
@lwouis How would you expect the user to end recording of modifier flags only shortcut? Currently the control relies on pressing a non-modifier key to end it. |
Please take a look at the issue-114 branch. |
Hey @Kentzo, thanks for working on implementing that feature! That's really nice to see! I took a look at the branch and its latest commit. There are quite a few changes and it's difficult for me to tell if that's correct since i'm unfamiliar with the codebase. On a short-term scale i can spend time manually testing if there is a way for you to share a build of that branch, or maybe i can build it myself easily? I'll check the build instructions later today when i'm not on my phone. I'm unfamiliar with the CI build/tests also, and that would be a big factor in assessing the branch i imagine |
At this time don't worry on validity of the code, just take a look at the changes from an end user perspective: that the feature is indeed works in a way you'd expect it. I.e. add it to your or some test project and see if new feature (-[SRRecorderControl allowsModifierFlagsOnlyShortcut]) does what you want. |
Hey @Kentzo I tested the branch today! Thanks for working on this so swiftly by the way, I really appreciate it! I was a bit overwhelmed recently but I finally found time today to test your work! I think it's a good first draft, however I see some issues:
|
IIRC the keyUp: will be sent for each change. So at the end there will be only modifier flag pressed. The control may require a user to hold the modifier flags for a few seconds to end the recording.
That is true. This issue can be partially addressed by the delegate of the RecorderControl. However, it won't allow implementations that have to accept both "^" and "⌥".
That is an oversight. Good catch! Please use the designated initializer for now. Perhaps it's better to subclass the control and provide implementation just for the modifier flags recorder. Side question: did you consider something like a pop-up menu instead for your use case? |
I'm afraid I don't know which initializer you are referring to here. I'm using
We are actually using a dropdown menu at the moment: In the future, I would love to use Also note, in the current screenshot above, how the |
|
I updated the code to use that constructor. It works everywhere now (!) except one use-case: When using |
Has there been any more work on this? |
I'm mostly gathering feedback at this moment. Please explain your use-case and what's missing in the current implementation. |
I'm making a program that listens for a global hotkey to mute/unmute the default input device. I want to be able to listen to key combinations like |
Would you like a key down or key up event? |
I need both for push-to-talk |
When there are multiple modifier flags, it's not straightforward when exactly the shortcut should be invoked. Say you have |
Thanks for the explanation. In my mind, |
The up and down events are triggered by the non-modifier key, i.e. Consider this scenario: you have a shortcut for I am thinking about this behavior: the shortcut is determined by the trailing key up-only events. E.g.
What do you think? |
I like the logic described by @bryanforbes. In @Kentzo example of
@Kentzo described an alternate logic:
I think it's more confusing than @bryanforbes proposal, because the user is able to press some modifiers, release them, but they don't trigger their defined shortcut because other keys were pressed in the flow. In the example (I assume both
So to recap:
|
You have to subclass style to disable the constraint and exclude if from the |
I subclassed class FitWidthStyle: RecorderControlStyle {
convenience init(_ identifier: String?, _ components: RecorderControlStyle.Components?) {
self.init(identifier: identifier, components: components)
// alwaysConstraints.first(where: { $0.identifier == "SR_alignmentGuide_suggestedWidth"})!.isActive = false
alwaysConstraints.forEach { $0.isActive = false }
displayingConstraints.forEach { $0.isActive = false }
}
} |
|
I tried to implement something around those guidelines. I couldn't get it to work. I think it's fine for now, especially since it would be messing with internals and making it risky on updates later down the line. I'm actually surprised nobody asked for a way to have a smaller control before. The current one is quite large by default By the way, regarding this ticket, I think you could close it. I have released a version of AltTab with ShortcutRecorder finally integrated a few days ago, and it seems to be working great for users 👍 |
I have removed the explicit constraint for intrinsic width. The control now relies on the Constraint for the height is still present as it's defined by the background assets. Other things you may try to make the control smaller:
|
Feel free to create a new issue to include a smaller style into the framework. I did that in the past and it worked. I included a complimentary "bonus" of $150 though :) |
@lwouis Can you check if |
@Kentzo I'm not sure what you mean. Currently in AltTab, I use |
Ah I see, indeed you do need I'm considering what'd be a better default for ShortcutRecorder in general. |
I would say least-priviledge is nice as a default, as long as people can opt-in the |
My thoughts exactly. Please take a look at the develop branch. |
You mean that commit, right? ae35edd I checked it and it seems nice to me. You let users set the You may want to note that some users in AltTab complained that sometimes the keyboard shortcuts stop working. I have tried my best but so far I have no idea how this is happening. It may simply be a macOS bug in that I still don't understand to this day for example, why these are happening; what triggers them. |
You may get that type, even if you didn't register for it explicitly, e.g. if system decides your handler takes too long to execute. Installed "tap" appears to be called synchronously by macOS''s input system. Thus I suggest to avoid doing any work in the handler and instead handle asynchronously.
Perhaps that's exactly what was happening? Ask your users to collect logs for your app next time it happens: SR traces the message. Note that traces are short lived, the best way to capture them is to reproduce the issue while |
Do you have any proof that this actually happens? It would seem like such an oversight from Apple not to document it if that's the case. Very interesting in any case. I'll try to make the code returns as fast as possible. Thank you for the info! |
I have encountered it myself while working on this feature. I then added the necessary ‘if’. The doc in the header says that these messages are out of band. |
Hi @Kentzo! So, we've been trying to identify a keyboard issue with AltTab's community for a while now. Today, I analyzed new logs from a user, and I see this message in these logs:
This message is coming from ShortcutRecorder. After digging a bit, I found the log line: ShortcutRecorder/Library/SRShortcutAction.m Line 395 in efde820
I'm quite puzzled as to how this is happening. From the caller (AltTab), we call get a let event_ = NSEvent(cgEvent: cgEvent) Then we create a new 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) At this point we call I can't imagine why the
Do you have any idea how this scenario would be happening? |
@lwouis Btw, try https://github.com/Kentzo/ShortcutRecorder/blob/develop/Library/SRShortcut.h#L80 to avoid some ugliness in your code to circumvent that |
I'm building an app that triggers when
⌥⇥
is pressed, and should then reacts when⌥
is released. I would like to let the user decide which shortcut they want to use.Using
RecorderControl
, the UI refuses to validate the⌥
as a key. It seems it is viewed only as a modifier, and can't be its own key. However in my current implementation, I'm using the properkeyCode
and it's working fine, so I don't think there is any technical limitation at play here. Same thing forShortcut(keyEquivalent: "⌥")
: it is returningnil
.Why can't a shortcut be just a modifier key like option or command? Is there a reason or is it just an oversight?
The text was updated successfully, but these errors were encountered: