Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
keyboard: turn down key repeat before going to lock screen
As mentioned here: https://twitter.com/wincent/status/1068234903811223552 Going to see if this can cure my lock screen woes. You can turn off key repeat with: defaults write -g KeyRepeat 300000 But you have to log out for it to take effect. I did some reverse engineering and header-file searching to figure out how: /System/Library/PreferencePanes/Keyboard.prefPane/Contents/MacOS/Keyboard Is forcing the changes to take effect immediately, and discovered some deprecated (sigh) APIs that hopefully will continue to exist for a while: NXSetKeyRepeatInterval() NXKeyRepeatInterval() NXOpenEventStatus() I bundled these up in a `dry` executable (short for "Don't Repeat Yourself") that can be used to set the key repeat delay in seconds. Not building or installing this automatically yet so that I can test it. Calling `dry` from the `karabiner-kill` and `karabiner-boot` scripts, and also switched to from running on systemWillSleep to screensDidLock, which allows us to cover both normal screen saver and sleep events with a single branch.
- Loading branch information
Showing
6 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
PREFIX ?= $(HOME) | ||
CFLAGS := -ansi -pedantic -Wall -Wextra ${CFLAGS} | ||
|
||
dry: main.c | ||
${CC} ${CFLAGS} \ | ||
-framework CoreFoundation \ | ||
-framework CoreServices \ | ||
-framework IOKit \ | ||
-o dry main.c | ||
|
||
install: | ||
install -m755 dry ${PREFIX}/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* dry (Don't Repeat Yourself) | ||
* | ||
* Usage: `dry 300` | ||
* | ||
* Sets the key repeat interval without requiring a logout. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <IOKit/hidsystem/event_status_driver.h> | ||
|
||
int main(int argc, const char * argv[]) { | ||
NXEventHandle handle; | ||
double interval; | ||
|
||
if (argc != 2) { | ||
printf("Expected 1 argument (key repeat in seconds); got %d\n", argc - 1); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
handle = NXOpenEventStatus(); | ||
if (!handle) { | ||
perror("NXOpenEventStatus"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
interval = NXKeyRepeatInterval(handle); | ||
printf("Old interval: %lf\n", interval); | ||
|
||
sscanf(argv[1], "%lf", &interval); | ||
printf("New interval: %lf\n", interval); | ||
|
||
NXSetKeyRepeatInterval(handle, interval); | ||
return 0; | ||
} |