[CLOSED] Keyboard commandline

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
User avatar
LegendDairy
Member
Member
Posts: 52
Joined: Sat Nov 06, 2010 10:42 am
Location: Antwerp (Belgium)

[CLOSED] Keyboard commandline

Post 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
Last edited by LegendDairy on Fri Nov 12, 2010 10:55 am, edited 1 time in total.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Keyboard commandline

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Keyboard commandline

Post by jal »

gerryg400 wrote:I'm not sure where you're having a problem.
A lack of required knowlegde, perhaps?


JAL
User avatar
LegendDairy
Member
Member
Posts: 52
Joined: Sat Nov 06, 2010 10:42 am
Location: Antwerp (Belgium)

Re: Keyboard commandline

Post 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
}
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Keyboard commandline

Post 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.
If a trainstation is where trains stop, what is a workstation ?
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Keyboard commandline

Post 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
User avatar
LegendDairy
Member
Member
Posts: 52
Joined: Sat Nov 06, 2010 10:42 am
Location: Antwerp (Belgium)

Re: Keyboard commandline

Post 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".
Last edited by LegendDairy on Thu Nov 11, 2010 7:57 am, edited 1 time in total.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Keyboard commandline

Post 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
User avatar
LegendDairy
Member
Member
Posts: 52
Joined: Sat Nov 06, 2010 10:42 am
Location: Antwerp (Belgium)

Re: Keyboard commandline

Post 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.
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Keyboard commandline

Post 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)
Last edited by chibicitiberiu on Thu Nov 11, 2010 11:00 am, edited 1 time in total.
Tibi,
Currently working on the Lux Operating System
User avatar
LegendDairy
Member
Member
Posts: 52
Joined: Sat Nov 06, 2010 10:42 am
Location: Antwerp (Belgium)

Re: Keyboard commandline

Post by LegendDairy »

It worked, ty for the help evryone :)
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Keyboard commandline

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Keyboard commandline

Post 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).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
LegendDairy
Member
Member
Posts: 52
Joined: Sat Nov 06, 2010 10:42 am
Location: Antwerp (Belgium)

Re: Keyboard commandline

Post 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 -_-')
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Keyboard commandline

Post 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.
Post Reply