Keyboard Function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gabemaiberger
Member
Member
Posts: 40
Joined: Tue Nov 13, 2012 2:54 pm

Keyboard Function

Post by gabemaiberger »

I just finished a function for getting a key from the keyboard. How would I make a table to use via xlat so I can translate a keyboard scancode to an ascii code?

Code: Select all

var myCat="marshmallow"
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Keyboard Function

Post by Brendan »

Hi,
gabemaiberger wrote:I just finished a function for getting a key from the keyboard. How would I make a table to use via xlat so I can translate a keyboard scancode to an ascii code?
Sadly, scan codes are not sequentially numbered, which makes them a pain in the neck for things like table lookups. Therefore the first thing you'll need to do is convert the scan code into a "key code" (where your "key codes" are sequentially numbered).

The next thing you want is a bitmap, where each bit in the bitmap says if the key is being held down or not. You need this so that you can determine the difference between "A", "control+A", "shift+A", "control+shift+A", etc.

Once you've got that done you want some sort of file that describes a keyboard layout. This file should include a list of which keys are "special" (e.g. left control, right control, left shift, caps lock, number lock, etc) and how those special keys effect state (e.g. both shift keys might cause the same "shift" flag to be set if they're held down). In addition to describing special keys, the file should also include many "key code to character" tables for each possible state. For example, you'd have one table for "key alone", one table for "shift+key", one for "caps_lock + key", one for "caps_lock + shift + key", one for "numb_lock + control + alt + key", etc.

Once this is done you'd need to create lots of different "keyboard layout files" - one for each possible keyboard layout. You also need something to tell the keyboard driver which keyboard layout is being used (which means having some sort of configuration variable/setting somewhere as this can't be auto-detected for PS/2 hardware).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
gabemaiberger
Member
Member
Posts: 40
Joined: Tue Nov 13, 2012 2:54 pm

Re: Keyboard Function

Post by gabemaiberger »

Thank you!!!

Code: Select all

var myCat="marshmallow"
Post Reply