Computer Hope

Software => Computer programming => Topic started by: glindhot on October 30, 2006, 05:04:43 PM

Title: ASCII for Alt key
Post by: glindhot on October 30, 2006, 05:04:43 PM
Keys have ASCII values, eg, Esc is ASCII 27, Enter is ASCII 13

As far as I can tell, the Alt key does not have an ASCII value,
but is there any ASCII combination, or whatever, that will produce it?  
Title: Re: ASCII for Alt key
Post by: Dusty on October 30, 2006, 11:44:56 PM
Will the keyboard scancode be of any use :-?

The scancode for Alt is hex 38
Title: Re: ASCII for Alt key
Post by: 2k_dummy on October 31, 2006, 01:27:24 PM
There are different sets of scancodes for different types of keyboards. I think set 3 is most common and is for the 101 key enhanced keyboard. Scancode 38 would be the ascii scancode for ALT. The hex code for ALT is 11 and EO 11 (left alt and right alt). You could probably stuff these values to the keyboard buffer to simulate the ALT key press. There is no true ascii value for the ALT key since it is a modifier for other key presses.
Title: Re: ASCII for Alt key
Post by: Rob Pomeroy on October 31, 2006, 01:28:14 PM
Quote
Keys have ASCII values
And I'm afraid that's where you'd be wrong.  Dusty's right; scan codes are not the same as ASCII codes.  Shift, ctrl, alt etc do not have corresponding ASCII codes; to test for them you'd need to use a keyboard interface library.
Title: Re: ASCII for Alt key
Post by: Rob Pomeroy on October 31, 2006, 01:28:55 PM
Oops.  Everybody jumps on the newbie...   ;D
Title: Re: ASCII for Alt key
Post by: 2k_dummy on October 31, 2006, 01:42:10 PM
If he can interface the keyboard, if the 3rd bit is set to 00, the keyboard will return the scancode set that it is using. If it is not as expected, he would have to create a lookup table to retrieve the proper scancode. Not exactly the simplest of tasks. The newer 120+ key keyboards have additional scancodes for the extra keys; however, the main keys must be backward compatable with the 101 enhanced keyboard.

This is not my forte! I'm gonna quit while I still can. ;D
Title: Re: ASCII for Alt key
Post by: Dusty on October 31, 2006, 03:39:28 PM
Maybe I over-simplified the use of scancodes, it's quite a complex subject for a new-comer and some of us older-comers.  I found this (http://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html) to be a good reference.  The entire site starting here (http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html) is good reading for a wet Sunday afternoon ;D

Good luck