photo
Jordan Sissel
geek

Tue, 07 Dec 2004

Terminals and meta characters

So it seems that there's two ways your terminal can send "meta" key combinations.

One method is to send escape + the character. So hitting ALT+J will send an escape character followed by 'J'.
Alternatively, your terminal might simply read the character value in and set it's most significant bit high before sending that byte to the terminal. What does does that mean?
Let's say you were to hit ALT+J this time. J, in ascii is 74 in ascii. This number represented in binary is: 01101010. Having alt held down sets the left-most (most significant) bit high, becoming 11101010.

Many terminals allow you to set which method of input it uses. XTerm, for instance, allows you through the menu accessed by control+leftclicking on the terminal (anywhere). Select "Meta sends Escape" and alt-key combinations will send escape+character. If "Meta sends Escape" is unchecked, then your terminal will set-high the most significant bit before sending the character.

Here's a perl oneliner that'll let you see what's going on. The output for mat is: char / ascii / binary where ascii is the hexadecimal value of what you entered, and binary is the binary representation. You'll notice that if "Meta sends Escape" is unchecked, then your terminal will set-high the most significant bit before sending the character.

#!/usr/bin/perl

system("stty raw -echo"); 
while (sysread(STDIN,$foo,1)) {
        printf("%s / %2x - ", ($foo =~ /[[:print:]]/ ? $foo : " "), ord($foo)); 
        print unpack("B32", pack("n", ord($foo))) . "\r\n" 
}

Comments: 0 (view comments)
Tags:
Permalink: /geekery/141
posted at: 16:20

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '08 Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials SSH Tunneling (Video)

Tag Cloud

Calendar

< December 2004 >
SuMoTuWeThFrSa
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
262728293031 

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati