Question:
What is the difference between a Keyboard Scan Code and an ASCII Code?
Rov
2011-01-27 09:44:08 UTC
Please include some references for further reading if you can. Kindly simplify the explanation too. Thank you!
Five answers:
anonymous
2011-01-27 11:41:12 UTC
A Keyboard Scan Code or KeyCode is the numerical value or index, of the key on the keyboard which you type. [1]



An ASCII code [2] is used to determine the character to which that key should correspond. ASCII, American Standard Code for Information Interchange uses codepages to map characters to designated character codes. The first 128 of which are always the same, the last 128 of which vary depending on which code page is used. See Extended ASCII. [3]



All keyboards will pass their scan codes to the Computer connected to the keyboard, the computer will then interpret what has been input. In Windows, the KeyCode will be translated to ASCII using the specified IME [Input Method Editor].



Look at your keyboard now.



On a standard, English, QWERTY 101/102 key keyboard: [4]

The Key at the position of the letter 'Q' has the key code with the numerical value 17.

That key will always pass 17, regardless of the language of the keyboard.



So if you were to use a French keyboard which uses the layout AZERTY: [5]

The same key at the same position this time with the letter 'A' on it, will have the same key code 17. That key will always pass 17.



A keyboard, does not decide what the keys mean or do. A keyboard does not decide its language either, the Operating System of the computer will. All keyboards will inform the OS of the 'default' language namely the one that is printed on the keys, but the OS can ignore this and you can change this freely.



So, depending on the setting of the OS, the key code is received, then the IME translates that code into an ASCII code. So if your OS was set up with a UK or US English keyboard set, then key 17 would be mapped to the ASCII character 'Q', [ASCI: 81] or 'q' [ASCII: 113] depending n whether Caps Lock is pressed or not; or if you had a French keyboard it would be mapped to 'A' [ASCII: 65] or 'a' [ASCII: 97] again depending on Caps Lock. [7]



Also just to note here, a KeyCode stays the same regardless of Caps Lock or any other key's state e.g. Alt or Ctrl etc. The ASCII code associated with the key will be different depending on these states with some keys having 3 or 4 ASCII codes associated which change depending on other key states e.g. the E key can produce: E, É, e and é.



Operating systems have default IME lists for you to choose from, with more usually available with language packs etc, and there are programs you can download [6] that let you create your own key map so you can reorder your keyboard as you see fit, instructing the OS what to map each key code to.



In Windows 7 for example to change your IME you would:

Go to your control panel, by clicking start, then typing control panel and hitting enter.

Then go to regional and language options

Then click keyboards and languages and choose change keyboards

On the dialog you can click add, to add more keyboard mappings.



No matter what you language you change the keyboard to, the keys will always have the same key codes as they were programmed with when the keyboard was built. The ASCII code the key corresponds to will only change.
?
2016-10-19 14:08:09 UTC
Keyboard Scan Code
Dan
2011-01-27 11:40:27 UTC
An ASCII code is a standardized number referring to a character in the ASCII character set. For example, ASCII code 65 is a capital A. ASCII codes exist independently of keyboards and so on - for example, the text in text files is made up of ASCII codes.



A Keyboard Scan Code says which key you pressed on a keyboard: it refers to the physical key in question, not the character it produces. For example, the key with 2 on it also contains @; 6 also contains ^, and so on. But regardless of which character you're generating, the scan code for any given key remains the same. Also, control keys such as Shift, Ctrl, Alt, etc. have their own scan codes, but there is no ASCII code associated with them.
rosette
2016-12-11 12:07:24 UTC
the known ASCII table has no symbols for the arrow keys. right that could be a short QBasic software I wrote years in the past to get the character codes decrease back by utilizing countless keys... 'KBRDCODE Ray Thomas June 2000 'A software to show the codes decrease back by utilizing the keyboard on a keypress CLS count style = 0 DO IF count style MOD 20 = 0 THEN GOSUB Titles DO UserIn$ = INKEY$ LOOP till UserIn$ <> "" PRINT LEN(UserIn$); TAB(10); LEFT$(UserIn$, a million); TAB(20); ASC(UserIn$) IF LEN(UserIn$) = 2 THEN UserIn$ = precise$(UserIn$, a million) hit upon CSRLIN - a million, 30 PRINT UserIn$; TAB(40); ASC(UserIn$) end IF count style = count style + a million LOOP till UserIn$ = CHR$(27) end Titles: PRINT PRINT TAB(10); "characteristics of UserIn$" PRINT PRINT "length"; TAB(10); "1st Char"; TAB(20); "Asc"; TAB(30); "2nd Char"; TAB(40); "ASC" PRINT return
?
2016-09-15 02:08:02 UTC
I don't believe that's right


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Search results for 'What is the difference between a Keyboard Scan Code and an ASCII Code?' (Questions and Answers)
4
replies
In C programming, what does & mean in front of a letter?
started 2010-01-26 07:08:55 UTC
programming & design
Loading...