Keyboard up, down and repeat

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
2100-OS

Keyboard up, down and repeat

Post by 2100-OS »

Using IRQ1, I want to be able to determine whether a key is being pressed (down) or is released (up). How can I handle this? (I'm using C with the regular outportb, inportb methods)

Thanks in advance
Slasher

Re:Keyboard up, down and repeat

Post by Slasher »

in the c program define an array for all the keys, 104+ of them
char Keys_layout[104];

in the isr for irq1,
NASM code,

Extern _keys_layout;

key_int:
cli
push eax
push edi
mov edi,_keys_layout ;put address of array in edi
in al,0x60
cmp al,0x80 ; compare to 128
jb make_key ; less than 128 so its a make code
sub al,0x80 ;subtract 128 from al to get the right offset into the array
add edi,al ;move to required offset
mov [edi], 0 ;key released
jmp finished
make_key:
add edi,al ;move to required offset
mov [edi], 1 ;key pressed
finished:
mov al,0x20
out 0x20,al
pop edi
pop eax
iret

this should work, although i haven't tested it and will require debuging(typed from the top of my head!)
2100-OS

Re:Keyboard up, down and repeat

Post by 2100-OS »

OK, I already push all the registers into a struct, so I can directly read from them using C, so I think the translation to C wouldn't be so difficult.
2100-OS

Re:Keyboard up, down and repeat

Post by 2100-OS »

It works, I didn't know about the 0x80, which makes sence, because normally a keyboard doesn't have more as 102-105 keys, so there is even a spare room.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Keyboard up, down and repeat

Post by distantvoices »

Hi:

Testing, if key was released or pressed is not that complicated: you just read in the scancode from port 60,
and then compare it with octal 0200. This tests, if the HIGH-Bit in the code is set. this looks like follows in pseudocode:

KEYBOARDPORT 0x60
KEYBOARDSTATUSPORT 0x64

ISRELEASED 0200
ISASCII 0177 (octal 0177 -> hex 0x7f -> dec 127)

unsigned int scancode;
int key_down;
scancode=inport(KEYBOARDPORT);
if(scancode&ISRELEASED)
key_down=0;
else
key_down=1;

if you want to extract a character with the scancode:
(assuming you have already defined a keymap)

character=keyswithoutshift[scancode&ISASCII];

bye


ps:
I have learned this from a. tanenbaums book. And of course I made my own interpretation after I have understood what a.tanenbaum has done in his code.

Another book worth to spend some bucks for: The Indispensable Hardware Book IV.

I am still in need of a bookcalled "the undocumented pc"
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Post Reply