Page 1 of 1

[KBD] capital W, T, U, V, and Y triggering line event

Posted: Thu Oct 11, 2012 2:53 pm
by mogana100
Hi

I have a nasty issue with my keyboard driver. The problem is, as the title states, that W, T, U, V, and Y are somehow recognized as home, end, ect (lets call it "aliasing")

What i already tried:

- unsigned char insted of char
- cast the values of KEND, KHOME, ect

what can I do to fix this bug?

my code (the "crippled" keymap is on purpose, because I have a german keyboard, and I want the keys ä, ö, ü to do nothing, also most assignments of the keys !, @, #, $, %, ^, &, * are different, and some of chars don't work)

Code: Select all

unsigned char keymap_noshift[] =
{
	NULL, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', BACKSPACE,
	TAB, 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 0, '+', ENTER, 0,
	'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0, 0, '#', 0, '\0',
	'y', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, ' ', 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	KHOME, KUP, KPGUP,'-', KLEFT, '5', KRIGHT, '+', KEND, KDOWN, KPGDN, KINS, KDEL, 0, 0, 0, 0, 0
};

unsigned char keymap_shift[] =
{
	NULL, ESC, '!', '\0', '\0', '\0', '\0', '\0', '\0', '(', ')', '=', '?', '`', BACKSPACE,
	TAB, 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 0, '*', ENTER, 0,
	'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0, 0, '\'', 0, '\0',
	'Y', 'X', 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, ' ', 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	KHOME, KUP, KPGUP, '-', KLEFT, '5',   KRIGHT, '+', KEND, KDOWN, KPGDN, KINS, KDEL, 0, 0, 0, 0, 0
};

unsigned k_get_key()
{
	unsigned char scancode;
	unsigned char buffer;
	
	scancode = inportb(0x60);
	
	if(scancode & 0x80)													//key released
	{
		scancode &= 0x7F;
		
		if(scancode == KRSHIFT || scancode == KLSHIFT)
		{
			kbd_shiftdown = 0;
		}
		return 0;
	}
	else																//key pressed
	{
		if(scancode == KRSHIFT || scancode == KLSHIFT)
		{
			kbd_shiftdown = 1;
			return 0;
		}
	}
	
	if(kbd_shiftdown)
	{
		buffer = keymap_shift[scancode];
	}
	else
	{
		buffer = keymap_noshift[scancode];
	}
	return buffer;
}	

void keyboard_handler()
{
	unsigned char key = k_get_key();
	
	switch(key)
	{
		case KUP:
		cursor_up();
		break;
		case KLEFT:
		cursor_left();
		break;
		case KRIGHT:
		cursor_right();
		break;
		case KDOWN:
		cursor_down();
		break;
		case KEND:
		cursor_end();
		break;
		case KHOME:
		cursor_home();
		break;
		case KINS:
		break;
		case KDEL:
		break;
		case KPGDN:
		break;
		case KPGUP:
		break;
	
		default:
			if(kbq.write >=	kbq.read + kbq_size)
			{
				return;
			}

			if(!key)
			{
				return;
			}

			*kbq.head = (char) key;
			kbq.head++;
			kbq.write++;
	
			if(kbq.head >= kbq.buffer + 32)
			{
				kbq.head = 0;
			}	
	}
};
greetings
mogana100

Re: [KBD] capital W, T, U, V, and Y triggering line event

Posted: Fri Oct 12, 2012 1:14 am
by Kevin
What does the definition of KHOME and friends look like?

Re: [KBD] capital W, T, U, V, and Y triggering line event

Posted: Fri Oct 12, 2012 7:49 am
by mogana100
Somehow, the problem just disappeared.
This were the definitions:

Code: Select all

#define NULL 			0
#define ESC 			27
#define BACKSPACE		'\b'
#define TAB 			'\t'
#define ENTER 			'\n'
#define RETURN 			'\r'
#define NEWLINE 		ENTER

//"F"-Keys

#define KESC 			1
#define KF1				0x80
#define KF2				(KF1 + 1)
#define KF3				(KF2 + 1)
#define KF4				(KF3 + 1)
#define KF5				(KF4 + 1)
#define KF6				(KF5 + 1)
#define KF7				(KF6 + 1)
#define KF8				(KF7 + 1)
#define KF9				(KF8 + 1)
#define KF10			(KF9 + 1)
#define KF11			(KF10 + 1)
#define KF12			(KF11 + 1)

//cursor keys
#define KINS			0x90
#define DEL				(KINS + 1)
#define KHOME			(KDEL +1)
#define KEND			(KHOME +1)
#define KPGUP			(KEND +1)
#define KPGDN			(KPGUP +1)
#define KLEFT			(KPGDN +1)
#define KUP				(KLEFT +1)
#define KDOWN			(KUP +1)
#define KRIGHT			(KDOWN +1)

//aux keys

#define KLCTRL			0x1D
#define KRCTRL			0x1D   
#define KLALT			0x38
#define KRALT			0x38   
#define KLSHIFT			0x2A
#define KRSHIFT			0x36
#define KCAPS_LOCK		0x3A
#define KSCROLL_LOCK	 0x46
#define KNUM_LOCK		0x45
#define KDEL			0x53
I changed them just for fun to:

Code: Select all

#define NULL 			0
#define ESC 			27
#define BACKSPACE		'\b'
#define TAB 			'\t'
#define ENTER 			'\n'
#define RETURN 			'\r'
#define NEWLINE 		ENTER

//"F"-Keys

#define KESC 			1
#define KF1				0x80
#define KF2				0x81
#define KF3				0x82
#define KF4				0x83
#define KF5				0x84
#define KF6				0x85
#define KF7				0x86
#define KF8				0x87
#define KF9				0x88
#define KF10			0x89
#define KF11			0x8A
#define KF12			0x8B

//cursor keys
#define KINS			0x90
#define DEL				0x91
#define KHOME			0x92
#define KEND			0x93
#define KPGUP			0x94
#define KPGDN			0x95
#define KLEFT			0x96
#define KUP				0x97
#define KDOWN			0x98
#define KRIGHT			0x99

//aux keys

#define KLCTRL			0x1D
#define KRCTRL			0x1D   
#define KLALT			0x38
#define KRALT			0x38   
#define KLSHIFT			0x2A
#define KRSHIFT			0x36
#define KCAPS_LOCK		0x3A
#define KSCROLL_LOCK	0x46
#define KNUM_LOCK		0x45
#define KDEL			0x53
and now, it works.

But: what caused this error (so I can avoid it next time)?
Could it be a kind of overflow caused by gcc, or have I messed it up?

EDIT:

a new problem showed up: now the capital S doesn't work (isn't recognized as a character)

Re: [KBD] capital W, T, U, V, and Y triggering line event

Posted: Fri Oct 12, 2012 7:59 am
by Kevin
Get an ASCII table, look up the value for 'S' and notice that you "overloaded" 0x53 to mean KDEL instead of 'S'. The same problem exists for your other special key constants.

And is it intentional that you have both DEL and KDEL?

Re: [KBD] capital W, T, U, V, and Y triggering line event

Posted: Fri Oct 12, 2012 11:18 am
by xenos
It seems that your keyboard handler doesn't handle 0xE0 scancode sequences at all... Some special keys generate two scancodes (0xE0 + something else), so you need to check whether there was an 0xE0 when a new scancode arrives.