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

Update Unshaky/ShakyPressPreventer.m #19

Closed
wants to merge 1 commit into from
Closed

Conversation

ghost711
Copy link

@ghost711 ghost711 commented Nov 4, 2018

More targeted approach for CMD+space issue after more investigation. Wrote up details of findings in comment.

More targeted approach CMD+space issue after more investigation. Wrote up details of findings in comment.
@aahung
Copy link
Owner

aahung commented Nov 5, 2018

Thanks for this PR, it feels like the only solution to go for.

Copy link
Owner

@aahung aahung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a million for this PR. I started couple of conversations you can find below. What do you think of them?


// The incoming keycode.
CGKeyCode keyCode = (CGKeyCode)CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);

// ignore unconfigured keys
if (keyDelays[keyCode] == 0) return event;

// keyboard type, dismiss if it is not built-in keyboard
if (ignoreExternalKeyboard) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why we need to move ignoreExternalKeyboard here. If the user types on an external keyboard, we do not have to extract the keyCode at all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I figured that the minority of people would be using this with an external keyboard, since the butterfly keyboard's issues are the main reason to use it, so I figured that would be the earlier exit. Maybe not though.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use MBP with external monitor and keyboard at office but Unshaky is always running. So this is useful option.

@@ -12,7 +12,7 @@
@implementation ShakyPressPreventer {
NSTimeInterval lastPressedTimestamps[128];
CGEventType lastPressedEventTypes[128];
CGEventFlags lastEventFlagsAboutModifierKeys[128];
//CGEventFlags lastEventFlagsAboutModifierKeys[128];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just delete it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, forgot to do that before pushing.

int64_t type = CGEventGetIntegerValueField(event, kCGKeyboardEventKeyboardType);
if (type != 58) return event;
}
/** Current version (for fork/pull request): */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not need this line either.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just forgot to delete again.


double stamp = [[NSDate date] timeIntervalSince1970];
Copy link
Owner

@aahung aahung Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this variable to currentTimestamp?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go ahead.


double stamp = [[NSDate date] timeIntervalSince1970];
double lastStamp = lastPressedTimestamps[keyCode];
Copy link
Owner

@aahung aahung Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this variable to lastTimestamp, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go ahead.

interfere in such case. So I add this following checking */
&& lastEventFlagsAboutModifierKeys[keyCode] == eventFlagsAboutModifierKeys
&& 1000 * ([[NSDate date] timeIntervalSince1970] - lastPressedTimestamps[keyCode]) < keyDelays[keyCode]) {
if (eventType == kCGEventKeyDown && lastPressedEventTypes[keyCode] == kCGEventKeyUp ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment about the styling, I found there is an extra space before the closing ).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I remembered to eliminate the first space since you mentioned not liking it earlier, but I missed that one.


if (lastPressedTimestamps[keyCode] != 0.0) {
if (lastStamp != 0.0) {
if (dismissNextEvent[keyCode]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the double stamp = [[NSDate date] timeIntervalSince1970]; here? Since this value is not needed until here, and for more key press event, this variable is not required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? Looks to me like it's determined at the last possible place before it's used.

@@ -57,58 +57,73 @@ - (void)loadIgnoreExternalKeyboard {
ignoreExternalKeyboard = [defaults boolForKey:@"ignoreExternalKeyboard"]; // default No
}

- (CGEventRef)filterShakyPressEvent:(CGEventRef)event {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't see why this line has been changed...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has it even been changed? I don't understand why it's been flagged.

@ghost711
Copy link
Author

ghost711 commented Nov 6, 2018

Hi, definitely most thanks are due to you for creating this, so thanks again.

I replied to all of your points, but I'm not familiar with the GitHub interface for this, so please feel free to just implement any of those changes as you see fit.

Most of them were just copying errors on my part with the exception of the one about performing the timestamp calculation later, which I believe is already done at the latest possible point.

@aahung
Copy link
Owner

aahung commented Nov 6, 2018

It just came to my mind that there is another scenario, which I think makes remembering lastMask necessary

The issue is with space key. CMD+SPACE is likely to be triggered multiple times if Unshaky chooses not to do anything...

@aahung
Copy link
Owner

aahung commented Nov 19, 2018

Since you have not yet responded to change requests and I plan to implement an improved version directly. So I am gonna close this PR, thanks!

@aahung aahung closed this Nov 19, 2018
aahung added a commit that referenced this pull request Nov 20, 2018
aahung added a commit that referenced this pull request Nov 20, 2018
aahung added a commit that referenced this pull request Nov 20, 2018
aahung added a commit that referenced this pull request Nov 20, 2018
Add a workaround for #1, improved on #19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants