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.
Tom

Keyboard input...How do I get keys?

Post by Tom »

Hello, I've just got the itoa function in FritzOS working.

Now, how do I get a key in PMode?

Thank you
Tom

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

Post by Tom »

in my key handeler...

I do
if ( scan >= ' ' )
putch( scan );

and when I type 'a' a * comes out, and so on.

whats wrong?
Tom

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

Post by Tom »

that is, not a* but '*' comes out
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 »

:D

well, your keyboard does not send ascii codes but SCANCODES instead (which is just numbers associated to the keys). The mapping from scancodes to ascii codes is keyboard-specific (i.e. different on a US keyboard than on a swiss one or french).

However, the repartition of scancodes along the keyboard is always the same (say, [ESC] will always be 1, left arrow is 75, etc.)

so what you have to do is defining
char charmap[]={ SCAN_1:'1','2','3','4', ... , SCAN_Q:'q','w','e','r','t','y' ... };

and then

Code: Select all

if (scan>128) putch(charmap[scan]);
Tom

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

Post by Tom »

oh, that's what I thought...I was thinking Isn't it ASCII?

Ok, ty
Tom

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

Post by Tom »

now I know how to get keys, is there a PMode way of detecting the keyboard scan-code type the user's using?
Tim

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

Post by Tim »

scancode = in(0x60)
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 »

I've seen many ppl in this forum sending something on the 61h port after reading the scancode with in al,60h.

That's something i've never done and my code always worked on real hardware (ranging from i386 to PIII), but when i come to BOCHS, the single "in 60,al" thing hangs the virtual PC after a few keystrokes ...

any clue ?
Whatever5k

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

Post by Whatever5k »

Hm...
I've seen the 0x61 stuff also in the MINIX source code, so I use it, too...
I have also some problems with Bochs and IRQ1, but I have no idea what's the problem...Bochs seems to suck ;)
Tom

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

Post by Tom »

   char _retchar;

   // Non-Shifted:
   char asciiNonSh[] = { NULL, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', NULL, 'a', 's', 'd', 'f', 'g', 'h',
   'j', 'k', 'l', ';', '\'', '`', NULL, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', NULL,'*',
   NULL, ' ' };

   _retchar = asciiNonSh[ scancode ];

and I can't get keys.
whats wrong? ( I am using the US 104 scancode, but have my kernel loading at 4000h without the a20 )

Thank you,
Tom

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

Post by Tom »

But:

when I do this:
char asciiNonSh[] = { NULL, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t' };

I can get keys.

???
gtsphere

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

Post by gtsphere »

i'm also having the same trouble, i can make a list of all the scancodes and if else if else if else then all, but i wanted to do the char array. I saw it somewhere once, but i couldn't figure out how it worked.

So basically,
you take your scanCode, put it into the array and it shold figure it out for you??

???

lost! heh. Does it actualyl know which one equals what?

thanks in advanced. And Tom, i hope you get this working cause your OS is really shippin up
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 »

i think you should *not* use NULL in your table as this is a void* (and thus it will not fit in a char array ... compiling with -Wall will certainly confirm this). try using '\0' instead ...
Tom

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

Post by Tom »

nope, didn't work. I run out of space I think after I put w in.
Post Reply