Page 1 of 1

[CLOSED] Keyboard commandline

Posted: Wed Nov 10, 2010 4:06 pm
by LegendDairy
Hi

I'm trying to write a keyboard commandline but it just won't work my idea is:
save a scancode in char
check if a new key is pressed(or the same key is pressed again)
if so i++, save the new scancode
else check again.
check if the scan code is enter if so break and return the string

How do i check if a new key(or the same key is pressed again) is pressed.

Or does someone have a sample function that a could look at? Or could someone be so kind to code a quick sample?:)

Thanks

Re: Keyboard commandline

Posted: Wed Nov 10, 2010 4:45 pm
by gerryg400
Legendmythe wrote:Hi

I'm trying to write a keyboard commandline but it just won't work my idea is:
save a scancode in char
check if a new key is pressed(or the same key is pressed again)
if so i++, save the new scancode
else check again.
check if the scan code is enter if so break and return the string

How do i check if a new key(or the same key is pressed again) is pressed.

Or does someone have a sample function that a could look at? Or could someone be so kind to code a quick sample?:)

Thanks
I'm not sure where you're having a problem. Wouldn't this just be a 'while (1)' loop with a 'break;' if the key '==' the 'Enter' key ?

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 4:08 am
by jal
gerryg400 wrote:I'm not sure where you're having a problem.
A lack of required knowlegde, perhaps?


JAL

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 6:04 am
by LegendDairy
I know this is off-topic but I can't continue with this topic unless this gets fixed.

I was working on my Keyboard driver and when I tried to link it I get this "kb.c:(.text+0x5f): undefined reference to `__stack_chk_fail'
" I've have that nowhere in my code?Can some help me?

Anyway here's the handler

Code: Select all

void keyboard_handler(struct regs *r)

{

    unsigned char scancode;
    unsigned int i;
    unsigned char string[60];
    
    for(i=0;i<59;i++) 
{
    scancode=inportb(0x60);
    if((kbdus[scancode])=1) {//enter='1'
    break;
    } else if (i<59) {
    string[i]=(kbdus[scancode]);
                     }
}
puts(string);//test it
}

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 6:17 am
by gerryg400
You're using c not pascal. Use

Code: Select all

==
to compare.

With regards the other problem, google will help. It's a very common problem solved with a gcc option. Can't remember the exact syntax.

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 7:36 am
by jal
Legendmythe wrote: I was working on my Keyboard driver and when I tried to link it I get this "kb.c:(.text+0x5f): undefined reference to `__stack_chk_fail'
" I've have that nowhere in my code?Can some help me?
Again, you demonstrate a total lack of required knowledge, and not knowing your tools.


JAL

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 7:38 am
by LegendDairy
gerryg400 wrote:You're using c not pascal. Use

Code: Select all

==
to compare.

With regards the other problem, google will help. It's a very common problem solved with a gcc option. Can't remember the exact syntax.
Thanks but as I thought I need a code to check if a key is pressed again because now it just keep using the old scancode so when i type "9" he types "999999999999999999999999999999999" then I he enter he types "111111111111111111"

Btw I had to add "-fno-stack-protector" but it's weird I never had to do that before even on the same code.
A lack of required knowlegde, perhaps?
Perhaps that is why I asked it?

BTW No one can know every possible error code and what to do. Also the first time you quoted the wrong post. And last but not least it is "Knowledge" and not "Knowlegde".

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 7:53 am
by jal
Legendmythe wrote:
A lack of required knowlegde, perhaps?
Perhaps that is why I asked it?
The thing is, you are supposed to have looked for the information yourself first, and not ask questions that indicate that you're in no way up to making an OS. Unfortunately for you, all your posts on this board indicate that you are just a beginning programmer, with little to no knowledge on, well, anything OS related.
BTW It is just "not knowing your tools".
No indeed it isn't, you don't seem to have any of the required skills.


JAL

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 8:04 am
by LegendDairy
The thing is, you are supposed to have looked for the information yourself first, and not ask questions that indicate that you're in no way up to making an OS. Unfortunately for you, all your posts on this board indicate that you are just a beginning programmer, with little to no knowledge on, well, anything OS related.
BTW It is just "not knowing your tools".
No indeed it isn't, you don't seem to have any of the required skills.


JAL
I was searching here for the last bits of information here that I couldn't find anywhere else, so do you want to help me or not
-if so here's my question:
how should I check if a key is pressed again and it isn't just the scancode from the last time.

-if not:
I'd rather like it if you just wouldn't comment, because the reason of a help forum is to help fill that "lack of knowledge", some of them are quit easy to fill others (like mine) take patient or else just ignore them and saying "This shows a lack of knowledge" won't help anyone.

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 10:51 am
by chibicitiberiu
You don't understand how interrupts work.

The function:
void keyboard_handler(struct regs *r)
is not your string input function. This function (if set up properly) should be launched every time you press a key, like an event.

Here is an idea how this might work:

Global variables: (don't forget volatile keyword) NewInterruptFired, ScanCode

String input function: set NewInterruptFired variable to 0
Wait until its value is changes.
Parse scancode
If it is a character, add it to your string

Keyboard Handler:
Set NewInterruptFired=1
Read from port 0x60, put in ScanCode variable
Tell PIC you are done


Again, don't forget 'volatile', otherwise the compiler will think you want to do an infinite loop, and replace it with while(1)

Re: Keyboard commandline

Posted: Thu Nov 11, 2010 10:58 am
by LegendDairy
It worked, ty for the help evryone :)

Re: Keyboard commandline

Posted: Fri Nov 12, 2010 6:15 am
by jal
Legendmythe wrote:I was searching here for the last bits of information here that I couldn't find anywhere else, so do you want to help me or not
-if so here's my question: how should I check if a key is pressed again and it isn't just the scancode from the last time.
As long as you haven't received a break, the key hasn't been released yet, right?
I'd rather like it if you just wouldn't comment, because the reason of a help forum is to help fill that "lack of knowledge"
Yes, but this forum is not for spoon-feeding newbies that do not have the required skills. We aren't teachers!


JAL

Re: Keyboard commandline

Posted: Fri Nov 12, 2010 7:30 am
by Combuster
jal wrote:this forum is not for spoon-feeding newbies that do not have the required skills. We aren't teachers!
It's not the complete truth: The required knowledge exists to protect newbies from themselves, and to protect us from slipping standards. The required knowledge is not completely about things you must know, it represents a set of skills and abilities you need to have to have a chance of success in OS development (where success does not involve copy and paste)
Legendmythe wrote:the reason of a help forum is to help fill that "lack of knowledge"
A forum can not fill a lack of skill, effort or intelligence. Any knowledge you seek is useless without it as it can not be applied later. And apparently you lack the skill (not finding the = vs == error), the effort (no visible attempt to debug), so what's helping you to just give you the answer? You'd bug us with an incomprehensible bug in the next 10 lines of code you'll write(?).


Your C and problem solving skills are below par, practice them. You really do not want to annoy us into being hostile (you succeeded doing that with at least one person already).

Re: Keyboard commandline

Posted: Fri Nov 12, 2010 10:43 am
by LegendDairy
The "=" wasn't an error it was just a quick code that a made and I couldn't test it. Of course I know the differnce between "=" and "==" I'm not that retarded.-_-' And sorry I wasted your "precious" time but ofcours ty to that one guy that help who didn't had to make 10 000 comment on how stupid I am and just made 1 post and solved the code and he didn't gave a code he explained how to code it.


Now let's close this topic so no1 will get annoyed anymore (this topic was solved 4 post ago -_-')

Re: Keyboard commandline

Posted: Fri Nov 12, 2010 11:44 am
by JamesM
Legendmythe wrote:The "=" wasn't an error it was just a quick code that a made and I couldn't test it. Of course I know the differnce between "=" and "==" I'm not that retarded.-_-' And sorry I wasted your "precious" time but ofcours ty to that one guy that help who didn't had to make 10 000 comment on how stupid I am and just made 1 post and solved the code and he didn't gave a code he explained how to code it.


Now let's close this topic so no1 will get annoyed anymore (this topic was solved 4 post ago -_-')
It was an error. If you honestly intended to perform an assignment inside that if statement, there was no comment to suggest such to the reviewer. So this in itself is a bug.

As to your questions - have you read the wiki page on the keyboard controller? bit 0 of inb(0x64) will be 1 when there is data available.