I need some help with keyboard scancodes

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
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

I need some help with keyboard scancodes

Post 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?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

Nope, that doesn't work, I have a feeling that this is because
the defined things are defined as hex numbers.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

I'm guessing you have a very oddly designed keyboard handler... :lol:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post 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?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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).
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post 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).
com1
Member
Member
Posts: 105
Joined: Sat Apr 28, 2007 11:57 am
Location: TN

keyboard struct

Post by com1 »

try using a keyboard struct, then create a char buffer, then fill in the buffer with simple scancodes
oh microsoft, microsoft, what souls you have dismayed
Post Reply