Skip to content

Commit

Permalink
- Allowing modifier keys + power key for all modifier keys except Fn
Browse files Browse the repository at this point in the history
 - Switched behavior of the two power key system events. The first event is now replaced and the second event is killed.
 - Fixes #9; PowerKey now works well with Command and Control
  • Loading branch information
pkamb committed Aug 23, 2013
1 parent 8e829b8 commit 6e3982e
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions PowerKey/PKPowerKeyEventListener.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,10 @@ CGEventRef copyEventTapCallBack(CGEventTapProxy proxy, CGEventType type, CGEvent
// Re-enable the event tap if it times out.
CGEventTapEnable(eventTap, true);
break;

case NSSystemDefined:
event = [refToSelf newPowerKeyEventOrUnmodifiedSystemDefinedEvent:event];
break;

default:
break;
}

return event;
}

Expand All @@ -117,7 +112,6 @@ - (CGEventRef)newPowerKeyEventOrUnmodifiedSystemDefinedEvent:(CGEventRef)systemE
The first power event seems to prompt the system to show the [Restart/Sleep/ShutDown] message.
The second power event (keyCode == NX_POWER_KEY), by itself, does not seem to prompt any system response.
When modifier keys are held, the NX_POWER_KEY event is often not sent. Fn + Power, especially, can cause unintended results if prevented. Not recommended.
This app only modifies the power key events when *no* modifier keys are held; the events and system proceed normally when any modifier keys are held.
IMPORTANT: Even if these events are prevented, the system WILL still turn off when the power key is held down for a few seconds!
*/

Expand All @@ -129,10 +123,10 @@ The second power event (keyCode == NX_POWER_KEY), by itself, does not seem to pr
keyFlags == 0 &&
keyState == 0 &&
keyRepeat == 0 &&
modifierKeys == 0)
!(modifierKeys & NSFunctionKeyMask))
{
//Kill the event, thereby blocking the system [Restart/Sleep/ShutDown] message.
systemEvent = CGEventCreate(NULL);
// Replace the event, thereby blocking the system [Restart/Sleep/ShutDown] message.
systemEvent = [self newPowerKeyReplacementEvent];
}

//Second Power key event
Expand All @@ -143,10 +137,10 @@ The second power event (keyCode == NX_POWER_KEY), by itself, does not seem to pr
keyFlags == 2560 &&
keyState == 1 &&
keyRepeat == 0 &&
modifierKeys == 0)
{
//Send a new replacement keystroke instead.
systemEvent = [self newPowerKeyReplacementEvent];
!(modifierKeys & NSFunctionKeyMask))
{
// Kill the event
systemEvent = CGEventCreate(NULL);
}

return systemEvent;
Expand Down

0 comments on commit 6e3982e

Please sign in to comment.