Page 1 of 1

keyboard handler

Posted: Mon Sep 30, 2002 12:18 pm
by gtsphere
i got a quick question, i have my keyboard handler written, and i am able to get the keys whether they are pressed or released, and i can 'if else' the scancode against the actual scancode keys to check if they pressed 'a' and if they did then output an 'a' to the screen

but i was wondering, is there a different way of doing this? as in just typing and it displays it on the screen? all in one string, rather than char by char? well what i mean is, rather than if(scancode == 01) etc etc to check the scancode for the key, can i just 'save' the entire string into an array or something simliar, and then just compare that string to a 'command', as in

allowuserinput( input );

if( input == "dir" )

that function, how would i go about doing that?

also, i have an idea, is it possible to just get the 'character' its self, like the actual A rather than the scancode or the ascii value?

thanks very much in advance
gtsphere

Re:keyboard handler

Posted: Mon Sep 30, 2002 12:30 pm
by PlayOS
I think that if all of your commands were no more than 4 chars (a DWORD) each then you could compare them as a 32bit number. But it is impossible to compare a string of chars using the '==' operator. You could write a function that would check a string against a list of commands and return a boolean result for use with the '==' operator, if the function returns false then you would have a normal string of text.

You can definately store each char until you recieve an end of input (enter) key and then display it in one go. once the string is complete in memory, you could zero terminate it and then pass it onto your printf() and display it that way. It really just depends on how you want your console driver to work.

Hope this helps.

Re:keyboard handler

Posted: Mon Sep 30, 2002 12:44 pm
by gtsphere
thank you, that actually did give me some ideas, so potentially, i can just

catch key, if enter clear, if not ouput, etc etc etc

and there wouldn't be much of a limitation there

but as for the commands, a DWORD. Now, i would just be like:

catchkeys
dir and while that happens, combine them into one int? as in 010203 so to speak?

i don't really have a good understand of DWORDS and such. could you help a little on that?? i would really aprreciate that!

thanks so much for all your help already

Re:keyboard handler

Posted: Mon Sep 30, 2002 9:07 pm
by PlayOS
OK, a DWORD is just the same as a long (sometimes an int is only 2 bytes) in C, it is 32 bits wide (4 bytes), a WORD is the same as a short in C, it is 16 bits wide (2 bytes), and a BYTE is the same as a char in C and it is 8 bits wide (1 byte).

You are right, each character (ascii code) is 8 bits wide so therefore you can combine the bytes to create a dword (4 bytes = 1 dword (or long)) and then you can test this value.

However I think that you might end up with commands that are more than 4 characters, you will also have to consider parameter passing and stuff like that. I would just store the input in a buffer until the end of input key is recieved and then pass all the input onto a function that will determine what to do with it, the function might check it against a list of commands and then also check that the parameter list is OK.

It will be more time consuming to have to manipulate bits to get the characters into a dword (long).

But you are the designer, so it is up to you. :)

Hope this helps you, Good Luck!