Saturday 20 February 2016

Keyboard Issues with OS X Lion And Above

This may well be old news to some people, but it is only a recent discovery for me.
I was working on a small application that needed a custom text input field, however, when I was testing it, I couldn't get certain keys to repeatedly call the MouseDown event, and yet others did.
I found this very frustrating, and I must admit, I was beginning to think that there was something wrong with my Macbook. So I fired up TextEdit and tried using the auto repeat feature of the keyboard there.
What I discovered was, certain keys allowed repeated input (turns out mainly only symbols), some keys (certain letters and all the numbers) just sent a single keydown event to the application and others showed a popup:

Apples useful character selector
So I found out what was happening, turns out that Apple had changed the behaviour of my keyboard to make it more iOS like. In normal day to day use, this would be fine: it's not often I need to write a string of repeating characters. However, for the development work I was doing, I didn't want to see this behaviour. Now, being a normal(?), rational person, I thought that I would find the solution to my problem in System Preferences. Surely Apple would have allowed quite a fundamental change to be toggled on or off there. But no, I could not find anything that would allow me to change this behaviour.
Next port of call... Google. After a quick search, I discovered another blog post, this one by Adam Dachis, over at Lifehacker. In that post, Adam describes the very same issue I was having, although it looks like it has been in existence for at least five years.
Adam also gives a very nice Terminal command that can turn this feature off (for those of you that are not familiar with Terminal, it can be found in Applications->Utilities):

defaults write -g ApplePressAndHoldEnabled -bool false

It is also possible to re-instate this behaviour by changing the 'false' to 'true':

defaults write -g ApplePressAndHoldEnabled -bool true

Once you have issued either of these commands, you will nee to re-open your window that you are using to type into as it needs to be initialised with this new setting.
I understand why Apple have made this change, not only does it merge the behaviour of iOS and OS X, but in an increasingly global society, it is nice to have easy access to these characters. However, I do think that they made a mistake by not allowing users to turn this off, or on, whenever it is required.