From b8dfa976ce796ede92dfefa6a39eb0a3b08acdce Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Thu, 28 Oct 2010 23:11:49 +0000 Subject: =?UTF-8?q?Added=20standard=20keyboard=20HID=20report=20scancode?= =?UTF-8?q?=20defines=20(thanks=20to=20L=C3=A1szl=C3=B3=20Monda).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'Demos/Host/LowLevel/KeyboardHost') diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c index f6946fbdd..c35a9034f 100644 --- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c @@ -154,8 +154,10 @@ void ReadNextReport(void) /* Indicate if the modifier byte is non-zero (special key such as shift is being pressed) */ LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0); + uint8_t KeyCode = KeyboardReport.KeyCode[0]; + /* Check if a key has been pressed */ - if (KeyboardReport.KeyCode) + if (KeyCode) { /* Toggle status LED to indicate keypress */ LEDs_ToggleLEDs(LEDS_LED2); @@ -163,14 +165,23 @@ void ReadNextReport(void) char PressedKey = 0; /* Retrieve pressed key character if alphanumeric */ - if ((KeyboardReport.KeyCode[0] >= 0x04) && (KeyboardReport.KeyCode[0] <= 0x1D)) - PressedKey = (KeyboardReport.KeyCode[0] - 0x04) + 'A'; - else if ((KeyboardReport.KeyCode[0] >= 0x1E) && (KeyboardReport.KeyCode[0] <= 0x27)) - PressedKey = (KeyboardReport.KeyCode[0] - 0x1E) + '0'; - else if (KeyboardReport.KeyCode[0] == 0x2C) - PressedKey = ' '; - else if (KeyboardReport.KeyCode[0] == 0x28) - PressedKey = '\n'; + if ((KeyCode >= HID_KEYBOARD_SC_A) && (KeyCode <= HID_KEYBOARD_SC_Z)) + { + PressedKey = (KeyCode - HID_KEYBOARD_SC_A) + 'A'; + } + else if ((KeyCode >= HID_KEYBOARD_SC_1_AND_EXCLAMATION) & + (KeyCode <= HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS)) + { + PressedKey = (KeyCode - HID_KEYBOARD_SC_1_AND_EXCLAMATION) + '0'; + } + else if (KeyCode == HID_KEYBOARD_SC_SPACE) + { + PressedKey = ' '; + } + else if (KeyCode == HID_KEYBOARD_SC_ENTER) + { + PressedKey = '\n'; + } /* Print the pressed key character out through the serial port if valid */ if (PressedKey) -- cgit v1.2.3