Keyboard driver

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
Jimferd

Keyboard driver

Post by Jimferd »

I'm planning on writing my keyboard driver in C. Do I need to map even the letter keys or just any special functions that I plan on using?
jrfritz

Re:Keyboard driver

Post by jrfritz »

I don't understand...but here is my ASCII US scancode array:

// Esc is 27 in ASCII
#define ESC         27
// Backspace in ASCII is '\b'
#define BACKSPACE '\b'
// tab is '\t'
#define TAB '\t'
// newline is '\n'
#define ENTER '\n'
// make newline a enter define, so you can use NEWLINE too
#define NEWLINE ENTER
// Make one for "return" - return to the start of the line:
#define RETURN '\r'

// Define non ASCII special scancodes
// Esc in scancode is 1
#define KESC         1
#define   KF1      0x80
#define   KF2      (KF1 + 1)
#define   KF3      (KF2 + 1)
#define   KF4      (KF3 + 1)
#define   KF5      (KF4 + 1)
#define   KF6      (KF5 + 1)
#define   KF7      (KF6 + 1)
#define   KF8      (KF7 + 1)
#define   KF9      (KF8 + 1)
#define   KF10      (KF9 + 1)
#define   KF11      (KF10 + 1)
#define   KF12      (KF11 + 1)

// Define Cursor Keys
#define   KINS      0x90
#define   KDEL      (KINS + 1)
#define   KHOME      (KDEL + 1)
#define   KEND      (KHOME + 1)
#define   KPGUP      (KEND + 1)
#define   KPGDN      (KPGUP + 1)
#define   KLEFT      (KPGDN + 1)
#define   KUP      (KLEFT + 1)
#define   KDOWN      (KUP + 1)
#define   KRIGHT      (KDOWN + 1)

// "Meta" keys
#define   KMETA_ALT   0x0200   // Alt is pressed
#define   KMETA_CTRL   0x0400   // Ctrl is pressed
#define   KMETA_SHIFT   0x0800   // Shift is pressed
#define   KMETA_ANY   (KMETA_ALT | KMETA_CTRL | KMETA_SHIFT)
#define   KMETA_CAPS   0x1000   // CapsLock is on
#define   KMETA_NUM   0x2000   // NumLock is on
#define   KMETA_SCRL   0x4000   // ScrollLock is on

// Define other keys
#define   KPRNT   ( KRT + 1 )
#define   KPAUSE   ( KPRNT + 1 )
#define   KLWIN   ( KPAUSE + 1 )
#define   KRWIN   ( KLWIN + 1 )
#define   KMENU   ( KRWIN + 1 )

#define   KRLEFT_CTRL      0x1D
#define   KRLEFT_SHIFT      0x2A
#define   KRCAPS_LOCK      0x3A
#define   KRLEFT_ALT      0x38
#define   KRRIGHT_ALT      0x38   // same as left
#define   KRRIGHT_CTRL      0x1D   // same as left
#define   KRRIGHT_SHIFT      0x36
#define   KRSCROLL_LOCK      0x46
#define   KRNUM_LOCK      0x45
#define   KRDEL         0x53

// Define the keypress define
#define KEYPRESS 0x80

// Define the max keyboard buffer
#define MAXKEYBUFFER 64

// Define the keyboard port for getting keys from the keyboard
#define KEYPORT 0x60


// data:
// Define keys:

// Non-Shifted scancodes to ASCII:
static const unsigned char asciiNonSh[] = { NULL, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '-', '=', BACKSPACE, TAB, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', ENTER, 0,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/', 0, 0, 0, ' ', 0, KF1, KF2, KF3, KF4, KF5, KF6, KF7, KF8, KF9, KF10, 0, 0,
KHOME, KUP, KPGUP,'-', KLEFT, '5', KRIGHT, '+', KEND, KDOWN, KPGDN, KINS, KDEL, 0, 0, 0, KF11, KF12 };

// Shifted scancodes to ASCII:
static const unsigned char asciiShift[] = { NULL, ESC, '!', '@', '#', '$', '%', '^', '&', '*', '(',
')', '_', '+', BACKSPACE, TAB, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', ENTER, 0,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N',
'M', '<', '>', '?', 0, 0, 0, ' ', 0, KF1, KF2, KF3, KF4, KF5, KF6, KF7, KF8, KF9, KF10, 0, 0,
KHOME, KUP, KPGUP, '-', KLEFT, '5', KRIGHT, '+', KEND, KDOWN, KPGDN, KINS, KDEL, 0, 0, 0, KF11, KF12 };
Jimferd

Re:Keyboard driver

Post by Jimferd »

Hrmm... that was slightly cryptic now wasnt it. You answered the question tho: Do I need to map all the letter keys (qwertyuiopasdfghjklzxcvbnm) or simply things like -[F1] - [F12]. But appearantly ya do :P. Thanks.
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

Re: Keyboard driver

Post by ehenkes »

What does this

// Define the keypress define
#define KEYPRESS 0x80

exactly mean? What is 0x80?
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Keyboard driver

Post by JohnnyTheDon »

Well, that was 7 years ago, so we can't be sure :)
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Keyboard driver

Post by egos »

ehenkes wrote:What is 0x80?
It's key up flag in set #1.

Now the good way is using set #2 with key up prefix 0xF0. See keyboard command 0xF0 (it's not a prefix) for more info.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Keyboard driver

Post by yemista »

What do you want your keyboard driver to do? Do you want it to just return raw scan codes? Do you want ti to convert to ascii and echo to the screen? Do you want it to be fully functional, or just functional enough to be able to use it?
User avatar
djsilence
Member
Member
Posts: 70
Joined: Wed Oct 01, 2008 11:18 am
Location: Ukraine, Kiev
Contact:

Re: Keyboard driver

Post by djsilence »

Don't think a ****, but in ukrainian schools English is TOO BAD!
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Keyboard driver

Post by jal »

The dead thread revival seems popular nowadays. Maybe the search feature or the post feature should give a big warning :).


JAL
Post Reply