Keyboard input...How do I get keys?

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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Keyboard input...How do I get keys?

Post by Pype.Clicker »

damn! this is veryveryvery weird ... maybe you should check it has no problem with compiling/linking/loading (for instance, print your array on the screen in the kernel or something alike ...

another trick would be to enter it as a string (" 1234567890-qwertyuiop ...")
Whatever5k

Re:Keyboard input...How do I get keys?

Post by Whatever5k »

try
char *keymap[] = {NULL, '1', ...};
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Keyboard input...How do I get keys?

Post by Pype.Clicker »

abless wrote: try
char *keymap[] = {NULL, '1', ...};
does this have chances to work ?? the [ESC] key has scancode #1, so i don't see where this will lead ...

Now something you should take care of is to map only key presses (not key releases :) ), thus something like

if (scancode & 0x80) {
// the key is released
} else {
putch(keymap[scancode]);
}

I also suggest you search in previous post, there was some explaination of how to handle extended scancodes (grey keys) like print screen, pause, num lock, etc. which have a 0xe0 prefix (if i remember well ;)
Whatever5k

Re:Keyboard input...How do I get keys?

Post by Whatever5k »

Code: Select all

char *keymap[] = {NULL, '1', ...};
This is wrong, of course. I do not know which devil drove me there ;)

This here should work:

Code: Select all

char keymap[][2]={
{NULL, NULL},
{ESC, NULL},
{'1', '!'},
.
.
};
This array holds the value for the non-shifted and the shifted scancodes...
Tom

Re:Keyboard input...How do I get keys?

Post by Tom »

;D Ok, Got my scancode to work, ( all the stuff you posted didn't help )

Now, all I have to do is work on the shifted keys, and release the code.

To all the people who want the code, it should be in
./include/keys.h
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Keyboard input...How do I get keys?

Post by Pype.Clicker »

and what was wrong, finally ??
Tom

Re:Keyboard input...How do I get keys?

Post by Tom »

I had to make it a static const unsigned char
Tom

Re:Keyboard input...How do I get keys?

Post by Tom »

now, how do I do shift?

I have all the keys for non-shifted and shifted defined, now just need to know how to detect a shift key is pressed when a letter or num is pressed.

How?
Whatever5k

Re:Keyboard input...How do I get keys?

Post by Whatever5k »

I cannot find your include/keys.h. Where is it?

Answer to your question:
Check if the key press is the SHIFT key:

Code: Select all

void kbd_handler(void)
{
int scan = scan_keyboard();
int key;
static int shift = 0;

if (scan == LSHIFT || scan == RSHIFT)
{
shift = 1; 
return;
}  

if (shift)
   key = keymap[scan][1];
else
   key = keymap[scan][0];
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Keyboard input...How do I get keys?

Post by Pype.Clicker »

oooh ... right . sorry, i didn't see you had a char* [] ... i thought it was a char [] :-)
Tom

Re:Keyboard input...How do I get keys?

Post by Tom »

I didn't release pk0.7 yet, that's why you can't fine the keys file ;)

I'll try the code, if it works i'lll release pk0.7

Thank you,
Tom

Re:Keyboard input...How do I get keys?

Post by Tom »

didn't work, abless.

Anyone else have code?
Tom

Re:Keyboard input...How do I get keys?

Post by Tom »

DUH forgot to use inportb :-[

trying abless's code now
Whatever5k

Re:Keyboard input...How do I get keys?

Post by Whatever5k »

[attachment deleted by admin]
Whatever5k

Re:Keyboard input...How do I get keys?

Post by Whatever5k »

[attachment deleted by admin]
Post Reply