# UP arrow key on Apple External Keyboard not recognized in OSX Lion terminal

keyboardosx lionterminalzsh

I have a MacBook pro for work use, and just got my hands on an apple USB keyboard.

When I am in the terminal, using the external keyboard ONLY I receive weird characters when I hit the UP arrow key. For instance, hitting the up arrow either enters a "~" (tilda) character. I tried changing the keyboard settings, and after doing that I started getting garbage characters "]]&D]]" and the like (that's not the actual error – it's the sort of character output you get when using a box remotely with the shell not configured properly for arrow keys).

The weird thing though is that while doing this with the external keyboard, the macbook's built in keyboard has no issues, all arrow keys work just fine. So this seems to be entirely related to the external keyboard.

Does anyone have any ideas what could be going on or how it could be fixed?

• It is possible that a little more detail would help answer this question. As it stands, I would approach this problem by trying to troubleshoot step-by-step, and here are some steps I would consider.

If you have access to a different Apple or other vendor's USB keyboard, attempt to use that to see if the problem recurs. It is possible that your particular keyboard and/or laptop USB ports have a problem.

I would check your terminal emulation type with:

\$ printenv TERM
xterm-256color


If it is not "xterm-256color" (the default for new windows in OS X's Terminal) then you may wish to consider setting your window to use that via Terminal's preferences. (This assumes you are using Terminal, and not an alternative, like iTerm.)

If you are using the "screen" utility or an SSH session, you may wish to try the same processes without them. If the problem repeats without them, you've gained some more information. If the problem doesn't repeat, then the configuration for those utilities or the interaction with your shell may be at issue, and you can look further into that.

Your tags indicate that Zsh might be in use. Determine if you have the same problem if you switch to bash (the default for OS X since Mac OS X 10.3 Panther) or another shell. A benefit of trying this that Bash and Zsh shouldn't share any or many configuration files. So, the possibility of a particular customized configuration for either shell being the culprit would be minimized.

If another shell doesn't have the same problem, you will need to determine whether the shell configuration or shell itself is the problem. If the shell you normally use has been customized, I'd back up and eliminate that customization before starting a new session. If the new session works, then it stands to reason there's a problem in your specific shell configuration.

You could also try the above steps with a fresh new OS X user account, which will inherit default settings from the localized user template for your language. This user account can be created and removed after testing via System Preferences > Users & Groups (as it is named in OS X Mountain Lion). This step would generally eliminate any other keyboard layouts that have been installed, as well as software that might modify keyboard behavior. Even if such software was installed for all users on the system, it is probably not set up as a Login Item for new users.