Page 1 of 1

I need some help with keyboard scancodes

Posted: Mon Apr 30, 2007 7:19 pm
by Pyrofan1
I have this code

Code: Select all

//NOTE: KEY_ESC and that stuff has been defined above
unsigned char keys[173]; //line 182

keys[KEY_ESC]=KEY_ESC;
keys[KEY_1]='1';
keys[KEY_2]='2';
keys[KEY_3]='3';
/*more here*/
Now, when I try to compile it I get a bunch of errors saying
keyboard.h:182: error: previous declaration of ‘keys’ was here
keyboard.h:237: error: invalid initializer
keyboard.h:238: warning: data definition has no type or storage class
keyboard.h:238: error: conflicting types for ‘keys’
How can I fix this?

Posted: Mon Apr 30, 2007 8:17 pm
by frank
You cant declare an array in a header file that is going to be included in more than one source file. You should declare the array in a source file and add an extern unsigned char keys[173]; to the header file.

Posted: Mon Apr 30, 2007 8:35 pm
by Pyrofan1
Nope, that doesn't work, I have a feeling that this is because
the defined things are defined as hex numbers.

Posted: Mon Apr 30, 2007 10:06 pm
by Brynet-Inc
I'm guessing you have a very oddly designed keyboard handler... :lol:

Posted: Mon Apr 30, 2007 10:10 pm
by Pyrofan1
Yeah, but I just scraped it and used the one from Brian's kernel tutorial. And while we're on the topic of keyboard drives I need help with the one I have now
keyboard.h

Code: Select all

void Putch(unsigned char c, unsigned char forecolour, unsigned char backcolour);
unsigned char getch()
{
	unsigned char oin=0;
	while(oin==0)
	{
		oin=inport(0x60);
	}

	outport(0x60,0xf4);
	outport(0x64,0x60);
	outport(0x64,0x20);
	return keys[oin];
}

unsigned char getche()
{
	unsigned char ch;
	ch=getch();
	Putch(ch,WHITE,BLACK);
	return ch;
}

char *getline()
{
	char *s=MemAlloc(50);
	unsigned char ch;
	while(ch!='\n')
	{
		ch=getche();
		*s=ch;
		s++;
	}
	return s;
}
as you can see I try to detect if a key has been press in getch, but that method doesn't work, does anybody have another way to detect if a key has been pressed?

Posted: Mon Apr 30, 2007 10:53 pm
by pcmattman
Use the keyboard IRQ. Then get the scancode (or convert to character), put it into a global variable, and then have getch return its contents (or wait, if the global is 0).

Posted: Mon Apr 30, 2007 11:08 pm
by Candy
You're initializing the array inside the header outside of any function, which doesn't work since it's an assignment, not an initialization.

Posted: Tue May 01, 2007 6:51 pm
by mathematician
pcmattman wrote:Use the keyboard IRQ. Then get the scancode (or convert to character), put it into a global variable, and then have getch return its contents (or wait, if the global is 0).
Better still, put it into a circular queue. (IRQ1 = int 9 unless you reprogram the PIC).

keyboard struct

Posted: Tue Jun 26, 2007 6:00 pm
by com1
try using a keyboard struct, then create a char buffer, then fill in the buffer with simple scancodes