mathiasbynens / dotfiles

:wrench: .files, including ~/.macos — sensible hacker defaults for macOS
https://mths.be/dotfiles
MIT License
30.38k stars 8.74k forks source link

Key repeat broken in macOS Sierra #687

Open jdsimcoe opened 8 years ago

jdsimcoe commented 8 years ago

Currently your script...

defaults write NSGlobalDomain KeyRepeat -int 0

...does not work in macOS Sierra. I've found that if I set things up here they work great:

screen shot 2016-07-14 at 10 20 05 am

Maybe they changed the preference file location or something.

hkdobrev commented 8 years ago

I've played with that a bit. I think 0 is no longer allowed as a value, but you could use 1, 2 etc. It makes it awfully fast then though. So they might have changed the scale. If you set it to the fastest Key Repeat and shortest initial delay and then read the values on the command line you get 2 and 15.

jdsimcoe commented 8 years ago

Tried doing this:

defaults write NSGlobalDomain KeyRepeat -int 1

And here's what I get:

2016-07-14 13:51:07.168 defaults[8647:1323339] Could not write domain Apple Global Domain; exiting
Tatsh commented 8 years ago

Use diff to compare before and after the changes (quickly). I can't imagine Apple changed this to no longer use NSUserDefaults. Maybe it's not in NSGlobalDomain anymore.

ktgvv commented 8 years ago

@hkdobrev If it was just a matter of forbidden value, replacing -int 0 with -float 0.001 would have done the trick and been a better way than -int 1 [except if -float was forbidden too]. ;)

mathiasbynens commented 8 years ago

@kvpb Yeah, using float seems to work (as in, fast keyboard repeat is enabled by it after a reboot):

defaults write NSGlobalDomain KeyRepeat -float 0.000000000001; defaults read-type NSGlobalDomain KeyRepeat; defaults read NSGlobalDomain KeyRepeat
Type is float
1e-12
jdsimcoe commented 8 years ago

@mathiasbynens That didn't seem to work.

mathiasbynens commented 8 years ago

@jdsimcoe It does for me on OS X El Capitan 10.11.6 (15G31) when rebooting afterwards.

jdsimcoe commented 8 years ago

@mathiasbynens I'm on macOS Sierra and that setting has changed or something because neither works at all... they must have changed the value.

mathiasbynens commented 8 years ago

@jdsimcoe Could you do this please?

  1. defaults read > a
  2. Open system preferences and change the setting to some other value than the default.
  3. defaults read > b
  4. Post diff a b here.
jdsimcoe commented 8 years ago

when I do this defaults read NSGlobalDomain KeyRepeat... I get 1e-12. When I do defaults read-type NSGlobalDomain KeyRepeat I get Type is float.

jdsimcoe commented 8 years ago

When I change it in the Preferences slider to the fastest value I do defaults read NSGlobalDomain KeyRepeat and get 2. And the type is integer.

jdsimcoe commented 8 years ago

@mathiasbynens defaults write NSGlobalDomain KeyRepeat -int 1 is the best I can do on macOS Sierra. The float just doesn't work.

ktgvv commented 8 years ago

I tried to take a wild guess, I don't have any Mac running macOS Sierra DP. If I get what @mathiasbynens and you @jdsimcoe say, my trick works for OS X 10.11.6 El Capitan but not macOS 10.12 DP4 Sierra. Maybe it actually is a matter of forbidden values. If -int works, -float maybe works too. Have you tried to defaults read NSGlobalDomain KeyRepeat with the slider put at different random values [not just the extremes and middle but some points here and there on the slider as well]? Right now, the question I'm asking myself is: did Apple reverse how it works [eg a bigger value means a higher rate] or just lock the values to a certain range [eg between 1 and 3]?, and if they did, does setting the slider's cursor to a point somewhere changes from an integer to a floating-point number [eg the extremes and middle at 1, 2 and 3, and the values between as 1.n and 2.n]? What bugs me is that either the slider is locked to a range of integers such as one integer by stopping point [which would explain why floating-point numbers don't work], the slider is locked to a range of integers by can accept floating-point numbers within that range or something escapes me.

wprater commented 8 years ago

Im on DP 5 and cannot seem to get the float to increase to speeds I was experiencing prior. also, you may need to tweak the InitialKeyRepeat value if you're getting no key repeat at all.

mickeys commented 8 years ago

On macOS build 16a294a, after setting values through the prefs panel (and verifying that it works in the terminal), these are the values I see:

% defaults read NSGlobalDomain ApplePressAndHoldEnabled
0
% defaults read NSGlobalDomain KeyRepeat
6
% defaults read NSGlobalDomain InitialKeyRepeat
25
ktgvv commented 8 years ago

@wprater InitialKeyRepeat's value is actually the time it takes for key repeat to initialize, that is how long you have to stay pressing the key before it automatically repeats. Maybe it needs to be set to a shorter value along KeyRepeat in macOS Sierra?

Also, I highly discommend setting InitialKeyRepeat lower than [ 7 ; 10 ]: hardly will you press a key that 2 or 3 characters will have been input; on my 2013 MacBook Pro, I can set it to 5 but I need to keep it around 10 on my 2010 MacBook. See my .osxmavericks for more.

anhkind commented 8 years ago

I can't find any command that works for macOS Sierra. Something must have changed ...

knpwrs commented 8 years ago

Same here. I just ugpraded to Sierra and I had to use... the GUI. And even then key repeat wasn't as fast as it was in El Capitan.

danemacmillan commented 8 years ago

@knpwrs I'm experiencing the same thing. They key repeat set from CLI appears to have no affect. Furthermore, after a reboot, the settings set from the GUI are lost, which means I need to set the preferences every time.

kdeldycke commented 8 years ago

For keyboards and mouse fine-tuning I'm exploring the use of https://pqrs.org/osx/karabiner/ . Only thing is a rewrite of the app is in progress for macOS Sierra support at: https://github.com/tekezo/Karabiner-Elements

jdsimcoe commented 8 years ago

@anhkind @knpwrs @danemacmillan @kdeldycke If you want to close to 0 try this:

defaults write NSGlobalDomain KeyRepeat -int 1

It is as close as you can get on macOS Sierra.

nuc commented 8 years ago

For me:

defaults write NSGlobalDomain KeyRepeat -int 1 defaults write NSGlobalDomain InitialKeyRepeat -int 10

makes it blazing fast. Even a bit too much, maybe.

blakeperdue commented 8 years ago

This is sad, I really liked having blazing fast key repeat. Has anyone found anything faster than

defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10

?

rjorgenson commented 8 years ago

Nothing i've tried has been as fast as keyrepeat 1 and initialkeyrepeat 10 =/ I miss lightning fast, but I imagine i'll get used to this speed shortly.

nuc commented 8 years ago

Just have in mind that you need to restart to apply the changes.

daz commented 8 years ago

Logging in and out is enough, don't need a full restart.

blaedj commented 8 years ago

I found that locking and unlocking my macbook was enough to apply the changes.

defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10

Seems as fast as before for me once I locked and unlocked my computer.

kirbysayshi commented 8 years ago

To be clear:

ezintz commented 8 years ago

Guys it works pretty awesome and it will be much to fast (at least for me (; ), I was not even able to type. How I got it working (also in iTerm), the min. value for KeyRepeat seems to be 1 and for InitialKeyRepeat 15 (for fast repeat) via System Preferences, by using the following values:

defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10

after it I closed all applications and explicit called the "Logout". Maybe you should also try to keep the System Preferences closed or at least not pointing to the keyboard configuration.

PS: I guess that float values are also working since the KeyRepeat value could be set on previous Mac OS X versions to float value.

kdeldycke commented 8 years ago

Regarding settings not being applied, I proposed some days ago to kill any instance of System Preferences to keep it from interfering. My PR is ready to merge at: https://github.com/mathiasbynens/dotfiles/pull/706

seclorum commented 8 years ago

I have come to this thread looking for a solution to my big issue with the macos Sierra update I've recently done, to find a dismal scene. It appears Apple has altered the scaling factors of keyboard repeat rate and wait-times, in a way that has implications for power users everywhere: If you rely on your keyboard as a principle means of interfacing with your computer, your system will now feel slower, no matter what you do.

Just in case anyone at Apple GIAF's, this nonsense with the key repeat rate has the (intended/un-?) impact of making Apple computers feel slower, for those of us who use keyboard-based applications (apparently there are still a few..) For example, I feel that through todays usage of vim, as opposed to yesterdays pre-Sierra update, my computer is about 3x slower than it was. In actuality, it is not - but it certainly is not sending keys to my apps as fast as it used to, so my apps spend a lot more time just sitting around .. waiting for keypress.

It really seems like a systematic failure on Apple's part to not understand this. I guess in the leap for features (sticky-/hot-keys are a feature now?) and the desire to push Siri everywhere, Apple is preparing us to have the courage required to .. get rid of the keyboard, too?

Tatsh commented 8 years ago

@seclorum Apple stopped supporting developers like us aeons ago. Look at Swift Playgrounds on the App store.

davidkuridza commented 8 years ago

This seems to work for me sort of as fast as in El Capitan:

defaults write NSGlobalDomain KeyRepeat -int 2
defaults write NSGlobalDomain InitialKeyRepeat -int 15

Can't make it go any faster than this unfortunately.

jdsimcoe commented 8 years ago

@davidkuridza defaults write NSGlobalDomain KeyRepeat -int 1 is faster.

davidkuridza commented 8 years ago

@jdsimcoe not in my case for some reason :)

tsdorsey commented 8 years ago

For posterities sake, the following are the macOS 10.12.1 step values for the keyRepeat and InitialKeyRepeat when you set them using the GUI. Lower values are faster.

keyRepeat: 120, 90, 60, 30, 12, 6, 2 InitialKeyRepeat: 120, 94, 68, 35, 25, 15

chrisRidgers commented 8 years ago

Ive had different behaviour on different devices: my MBPro updated and appeared to have either disabled key repeat or set it to repeat after 30 seconds.

My Mac Mini has updated and all appears to be as before: at least in that it works:

Values are currently:

    - InitialKeyRepeat: 15
    - KeyRepeat: 2
jakeonrails commented 8 years ago

Hey everybody.

I just got off the phone with Apple Support about this issue. Rubber ducking the problem with a very helpful agent named Zach, I resolved this problem for my computer on OS X Sierra.

The trick was:

defaults write -g KeyRepeat -int 1

followed by a reboot.

Does that fix it for anyone else? I think the reboot step is critical.

Tatsh commented 8 years ago

Good but I hate rebooting.

tsdorsey commented 8 years ago

It is frustrating that the preferences pane doesn't need to reboot the machine. Wonder what command/API it is using to trigger the update realtime...

jaswrks commented 7 years ago

@jakeonrails Thanks for that! Worked like a charm on a Mac Pro.

Here's what I ended up with to correct the problem, using your suggestion.

# Set a blazingly fast keyboard repeat rate.
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false;
defaults write -g InitialKeyRepeat -int 15; # Anything lower than 15 seems too fast.
defaults write -g KeyRepeat -int 2; # You can go as low as 1, but that's too darn fast for me.
alexhayes commented 7 years ago

I had a slightly different problem, I had fast repeat on my MBP keyboard but no key repeat on my DAS keyboard (I'm using a new 2016 MBP - switching from Ubuntu to OSX, oh the joy, the daily struggles FFS).

Initially my KeyRepeat was set to 0.9 which, after reading through this thread and others, appears to be an invalid value. In any case, setting KeyRepeat to 1 as follows didn't fix the issue after a reboot.

defaults write -g ApplePressAndHoldEnabled -bool false;
defaults write -g InitialKeyRepeat -int 10;
defaults write -g KeyRepeat -int 1;

This did at least make the key repeat on my DAS keyboard work, but it made both my DAS and the MPB keyboard repeat way too slow. It was taking at least 500ms for each repeat which is useless.

What did work was to disable 'Slow Keys' in Accessibility Preferences and then adjust the sliders in Preferences so that they were both the highest values.

Adjusting the sliders to the highest values caused the following;

⇒  defaults read -g KeyRepeat
2
⇒  defaults read -g InitialKeyRepeat
15

KeyRepeat now working on both the MPB keyboard and my DAS keyboard. It's not super fast, but it's at least working...


It seems that if I then went and did the following;

defaults write -g InitialKeyRepeat -int 10;
defaults write -g KeyRepeat -int 1;

and rebooted, the repeat rate would actually be much worse.

jakeonrails commented 7 years ago

@alexhayes here are my settings:

$ defaults read -g ApplePressAndHoldEnabled
2016-12-19 14:40:44.933 defaults[20505:13529518]
The domain/default pair of (kCFPreferencesAnyApplication, ApplePressAndHoldEnabled) does not exist
$ defaults read -g InitialKeyRepeat
15
$ defaults read -g KeyRepeat
1

I definitely noticed the difference between 1 and 2 - 1 is 50% of the time as 2, about 15ms. Maybe try your initial key repeat at 15 like mine - maybe one is a multiplier for the other? And reboot :D Good luck sir, I hope this fixes it for you.

lobster-jack commented 7 years ago

FOUND THE SOLUTION

After being desperate myself, I tried out every single solution which was posted here, but nothing helped. Afterwards, I made a single last try:

Deactivate "PressAndHoldEnabled" in the GUI of System-Settings>"Input-Help" (then choose keyboard, and uncheck the checkbox at the bottom)

bildschirmfoto 2017-01-03 um 14 39 03

I also used

$ defaults read -g InitialKeyRepeat 15 $ defaults read -g KeyRepeat 1

Those 2 adjustments only worked after disabling the checkbox in my first step.

mathiasbynens commented 7 years ago

@lobster-jack Thanks! I haven’t been able to confirm this myself yet (since everything is already working on my end), but here’s some more info:

in the GUI of System-Settings>"Input-Help"

For those running macOS in English, that’s System PreferencesAccessibility.

(then choose keyboard, and uncheck the checkbox at the bottom)

This is the checkbox that says “Enable Slow Keys”.

prewk commented 7 years ago

It baffles me that everyone in this thread ignores the fact that defaults read -g InitialKeyRepeat -int 10 returns an error: The domain/default pair of (kCFPreferencesAnyApplication, InitialKeyRepeat) does not exist.

davidkuridza commented 7 years ago

@prewk I believe you mean write? It should be defaults read -g InitialKeyRepeat and defaults write -g InitialKeyRepeat -int 10

prewk commented 7 years ago

..and suddenly - the error disappeared. I think I interpreted an answer in this thread wrong and made an incorrect assumption. Thanks, and sorry :)

janka102 commented 7 years ago

Doesn't seem anyone mentioned this yet, but when doing defaults write -g KeyRepeat -int N and N is 0 or 1, then the slider in System Preferences shows up in the middle, but the actual tested key repeat is indeed blazing fast. And I got that working after just a Log Out, which is faster than a full reboot, so if you are like me and wanted to test different values out, you don't have to wait for a full reboot.

lucascaton commented 7 years ago

Finally found a solution! 🎉

defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

Then, close the app and re-open it.