How to type non-printable ASCII characters in Mac OS X Terminal?

16

6

To communicate with a serial-type device over a telnet socket, I need to type the null character (ASCII 0) and all other non-printable ASCII characters.

On Windows, you hold ALT and type the ASCII code.

How do I do this on Mac OS X?

davidcann

Posted 2011-03-17T17:40:03.427

Reputation: 263

Question was closed 2016-11-21T18:36:53.980

Type null character in terminal – phuclv – 2016-11-17T16:51:11.330

Answers

18

CtrlSpace sends ASCII NUL.

For the general case, System Preferences > Keyboard > Input Sources, scroll down the list and select Unicode Hex Input.

You can then use CmdShiftSpace (and, if you disable Spotlight's use of it, CmdSpace) to switch between input modes or assign it a keyboard shortcut of its own (and presumably another to switch back) in System Preferences > Keyboard > Keyboard Shortcuts.

Once Unicode Hex Input is enabled, you hold down Option and type the 4 digit hex code; on releasing Option it should be typed. You could stay in that mode as long as you don't need any characters beyond U+007F (or of course type them all with hex input instead of, say, Optione e to type é).

geekosaur

Posted 2011-03-17T17:40:03.427

Reputation: 10 195

For Mac OS X it's Shift + Alt + Space – None – 2014-07-21T18:01:14.110

In my case, I had to enter a DLE character (Unicode 0x10) onto the command-line. DLE is the same thing as Ctrl-P which, in any program that uses readline sees as a "scroll to previous entry" command, so it's the same thing as pressing . In order to type a DLE character on my terminal, I had to do Ctrl-V then Opt-0-0-1-0 and I got a character that looks on the screen like ^P. – Christopher Schultz – 2016-09-29T15:29:13.797

1Great, thanks! Note to others: on my system, the default shortcut key was Option Cmd Space. – davidcann – 2011-03-17T18:55:43.550

2

In many CLI/TUI applications you can press CtrlV in order to tell the application to accept the next keypress as raw character codes instead of invoking its normal function.

Ignacio Vazquez-Abrams

Posted 2011-03-17T17:40:03.427

Reputation: 100 516