Index: uspace/drv/usbkbd/Makefile
===================================================================
--- uspace/drv/usbkbd/Makefile	(revision 2b9646335943ad9872daddeaffee9b749d2830c1)
+++ uspace/drv/usbkbd/Makefile	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
@@ -29,11 +29,27 @@
 USPACE_PREFIX = ../..
 LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
-EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
+EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
 BINARY = usbkbd
+SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd
 
 SOURCES = \
 	main.c \
 	descparser.c \
-	descdump.c
+	descdump.c \
+	conv.c \
+	us_qwerty.c \
+	us_dvorak.c \
+	cz.c
 
 include $(USPACE_PREFIX)/Makefile.common
+
+us_qwerty.c:
+	ln -snf $(SRV_KBD)/layout/$@ $@
+
+us_dvorak.c:
+	ln -snf $(SRV_KBD)/layout/$@ $@
+
+cz.c:
+	ln -snf $(SRV_KBD)/layout/$@ $@
+
+
Index: uspace/drv/usbkbd/conv.c
===================================================================
--- uspace/drv/usbkbd/conv.c	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
+++ uspace/drv/usbkbd/conv.c	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <io/keycode.h>
+#include <stdint.h>
+#include "conv.h"
+
+static int scanmap_simple[255] = {
+
+//	[0x29] = KC_BACKTICK,
+
+//	[0x02] = KC_1,
+//	[0x03] = KC_2,
+	[0x04] = KC_A,
+	[0x05] = KC_B,
+	[0x06] = KC_C,
+	[0x07] = KC_D,
+	[0x08] = KC_E,
+	[0x09] = KC_F,
+	[0x0a] = KC_G,
+	[0x0b] = KC_H,
+	[0x0c] = KC_I,
+	[0x0d] = KC_J,
+	[0x0e] = KC_K,
+	[0x0f] = KC_L,
+	[0x10] = KC_M,
+	[0x11] = KC_N,
+	[0x12] = KC_O,
+	[0x13] = KC_P,
+	[0x14] = KC_Q,
+	[0x15] = KC_R,
+	[0x16] = KC_S,
+	[0x17] = KC_T,
+	[0x18] = KC_U,
+	[0x19] = KC_V,
+	[0x1a] = KC_W,
+	[0x1b] = KC_X,
+	[0x1c] = KC_Y,
+	[0x1d] = KC_Z,
+
+	[0x1e] = KC_1,
+	[0x1f] = KC_2,
+	[0x20] = KC_3,
+	[0x21] = KC_4,
+	[0x22] = KC_5,
+	[0x23] = KC_6,
+	[0x24] = KC_7,
+	[0x25] = KC_8,
+	[0x26] = KC_9,
+	[0x27] = KC_0,
+	
+	[0x28] = KC_ENTER,
+	[0x29] = KC_ESCAPE,
+	[0x2a] = KC_BACKSPACE,
+	[0x2b] = KC_TAB,
+	[0x2c] = KC_SPACE,
+
+	[0x2d] = KC_MINUS,  // same as DASH? (- or _)
+	[0x2e] = KC_EQUALS,
+	[0x2f] = KC_LBRACKET,
+	[0x30] = KC_RBRACKET,
+	[0x31] = KC_BACKSLASH,
+	//[0x32] = KC_,	// TODO: HASH??? maybe some as 0x31 - backslash
+	[0x33] = KC_SEMICOLON,
+	[0x34] = KC_QUOTE,  // same as APOSTROPHE? (')
+	[0x35] = KC_BACKTICK,  // same as GRAVE ACCENT?? (`)
+	[0x36] = KC_COMMA,
+	[0x37] = KC_PERIOD,
+	[0x38] = KC_SLASH,
+
+	[0x39] = KC_CAPS_LOCK,
+	
+	[0x3a] = KC_F1,
+	[0x3b] = KC_F2,
+	[0x3c] = KC_F3,
+	[0x3d] = KC_F4,
+	[0x3e] = KC_F5,
+	[0x3f] = KC_F6,
+	[0x40] = KC_F7,
+	[0x41] = KC_F8,
+	[0x42] = KC_F9,
+	[0x43] = KC_F10,
+	[0x44] = KC_F11,
+	[0x45] = KC_F12,
+	
+	[0x46] = KC_PRTSCR,
+	[0x47] = KC_SCROLL_LOCK,
+	[0x48] = KC_PAUSE,
+	[0x49] = KC_INSERT,
+	[0x4a] = KC_HOME,
+	[0x4b] = KC_PAGE_UP,
+	[0x4c] = KC_DELETE,
+	[0x4d] = KC_END,
+	[0x4e] = KC_PAGE_DOWN,
+	[0x4f] = KC_RIGHT,
+	[0x50] = KC_LEFT,
+	[0x51] = KC_DOWN,
+	[0x52] = KC_UP,
+	
+	//[0x64] = // some funny key
+	
+	[0xe0] = KC_LCTRL,
+	[0xe1] = KC_LSHIFT,
+	[0xe2] = KC_LALT,
+	//[0xe3] = KC_L	// TODO: left GUI
+	[0xe4] = KC_RCTRL,
+	[0xe5] = KC_RSHIFT,
+	[0xe6] = KC_RALT,
+	//[0xe7] = KC_R	// TODO: right GUI
+	
+};
+
+unsigned int usbkbd_parse_scancode(int scancode)
+{
+//	console_ev_type_t type;
+	unsigned int key;
+	int *map = scanmap_simple;
+	size_t map_length = sizeof(scanmap_simple) / sizeof(int);
+
+	/*
+	 * ACK/NAK are returned as response to us sending a command.
+	 * We are not interested in them.
+	 */
+//	if (scancode == SC_ACK || scancode == SC_NAK)
+//		return;
+
+//	if (scancode == 0xe0) {
+//		ds = ds_e;
+//		return;
+//	}
+
+//	switch (ds) {
+//	case ds_s:
+//		map = scanmap_simple;
+//		map_length = sizeof(scanmap_simple) / sizeof(int);
+//		break;
+//	case ds_e:
+//		map = scanmap_e0;
+//		map_length = sizeof(scanmap_e0) / sizeof(int);
+//		break;
+//	default:
+//		map = NULL;
+//		map_length = 0;
+//	}
+
+//	ds = ds_s;
+
+//	if (scancode & 0x80) {
+//		scancode &= ~0x80;
+//		type = KEY_RELEASE;
+//	} else {
+//		type = KEY_PRESS;
+//	}
+
+	if ((scancode < 0) || ((size_t) scancode >= map_length))
+		return -1;
+
+	key = map[scancode];
+//	if (key != 0)
+//		kbd_push_ev(type, key);
+	return key;
+}
Index: uspace/drv/usbkbd/conv.h
===================================================================
--- uspace/drv/usbkbd/conv.h	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
+++ uspace/drv/usbkbd/conv.h	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief USB Scancode parser.
+ */
+
+#ifndef USBHID_CONV_H_
+#define USBHID_CONV_H_
+
+unsigned int usbkbd_parse_scancode(int scancode);
+
+#endif
Index: uspace/drv/usbkbd/layout.h
===================================================================
--- uspace/drv/usbkbd/layout.h	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
+++ uspace/drv/usbkbd/layout.h	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak 
+ * (copied from /uspace/srv/hid/kbd/include/layout.h)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup usb
+ * @brief 
+ * @ingroup
+ * @{
+ */
+/** @file
+ */
+
+#ifndef USBHID_LAYOUT_H_
+#define USBHID_LAYOUT_H_
+
+#include <sys/types.h>
+#include <io/console.h>
+
+typedef struct {
+	void (*reset)(void);
+	wchar_t (*parse_ev)(console_event_t *);
+} layout_op_t;
+
+extern layout_op_t us_qwerty_op;
+extern layout_op_t us_dvorak_op;
+extern layout_op_t cz_op;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/drv/usbkbd/main.c
===================================================================
--- uspace/drv/usbkbd/main.c	(revision 2b9646335943ad9872daddeaffee9b749d2830c1)
+++ uspace/drv/usbkbd/main.c	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
@@ -41,6 +41,9 @@
 #include <usb/devreq.h>
 #include <usb/descriptor.h>
+#include <io/console.h>
 #include "descparser.h"
 #include "descdump.h"
+#include "conv.h"
+#include "layout.h"
 
 #define BUFFER_SIZE 32
@@ -91,8 +94,149 @@
 
 /*
+ * TODO: Move somewhere else
+ */
+/*
+#define BYTES_PER_LINE 12
+
+static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
+{
+	printf("%s\n", msg);
+	
+	size_t i;
+	for (i = 0; i < length; i++) {
+		printf("  0x%02X", buffer[i]);
+		if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
+		    || (i + 1 == length)) {
+			printf("\n");
+		}
+	}
+}
+*/
+/*
+ * Copy-paste from srv/hid/kbd/generic/kbd.c
+ */
+
+/** Currently active modifiers. 
+ *
+ * TODO: put to device?
+ */
+static unsigned mods = KM_NUM_LOCK;
+
+/** Currently pressed lock keys. We track these to tackle autorepeat.  
+ *
+ * TODO: put to device? 
+ */
+static unsigned lock_keys;
+
+#define NUM_LAYOUTS 3
+
+static layout_op_t *layout[NUM_LAYOUTS] = {
+	&us_qwerty_op,
+	&us_dvorak_op,
+	&cz_op
+};
+
+static int active_layout = 0;
+
+static void kbd_push_ev(int type, unsigned int key)
+{
+	console_event_t ev;
+	unsigned mod_mask;
+
+	// TODO: replace by our own parsing?? or are the key codes identical??
+	switch (key) {
+	case KC_LCTRL: mod_mask = KM_LCTRL; break;
+	case KC_RCTRL: mod_mask = KM_RCTRL; break;
+	case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
+	case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
+	case KC_LALT: mod_mask = KM_LALT; break;
+	case KC_RALT: mod_mask = KM_RALT; break;
+	default: mod_mask = 0; break;
+	}
+
+	if (mod_mask != 0) {
+		if (type == KEY_PRESS)
+			mods = mods | mod_mask;
+		else
+			mods = mods & ~mod_mask;
+	}
+
+	switch (key) {
+	case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
+	case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
+	case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
+	default: mod_mask = 0; break;
+	}
+
+	if (mod_mask != 0) {
+		if (type == KEY_PRESS) {
+			/*
+			 * Only change lock state on transition from released
+			 * to pressed. This prevents autorepeat from messing
+			 * up the lock state.
+			 */
+			mods = mods ^ (mod_mask & ~lock_keys);
+			lock_keys = lock_keys | mod_mask;
+
+			/* Update keyboard lock indicator lights. */
+			// TODO
+			//kbd_ctl_set_ind(mods);
+		} else {
+			lock_keys = lock_keys & ~mod_mask;
+		}
+	}
+/*
+	printf("type: %d\n", type);
+	printf("mods: 0x%x\n", mods);
+	printf("keycode: %u\n", key);
+*/
+	
+	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
+		key == KC_F1) {
+		active_layout = 0;
+		layout[active_layout]->reset();
+		return;
+	}
+
+	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
+		key == KC_F2) {
+		active_layout = 1;
+		layout[active_layout]->reset();
+		return;
+	}
+
+	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
+		key == KC_F3) {
+		active_layout = 2;
+		layout[active_layout]->reset();
+		return;
+	}
+	
+	ev.type = type;
+	ev.key = key;
+	ev.mods = mods;
+
+	ev.c = layout[active_layout]->parse_ev(&ev);
+
+	printf("Sending key %d to the console\n", ev.key);
+	assert(console_callback_phone != -1);
+	async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
+}
+/*
+ * End of copy-paste
+ */
+
+	/*
+	 * TODO:
+	 * 1) key press / key release - how does the keyboard notify about release?
+	 * 2) layouts (use the already defined), not important now
+	 * 3) 
+	 */
+
+/*
  * Callbacks for parser
  */
 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
-                                    uint8_t modifiers, void *arg)
+    uint8_t modifiers, void *arg)
 {
 	printf("Got keys: ");
@@ -100,4 +244,9 @@
 	for (i = 0; i < count; ++i) {
 		printf("%d ", key_codes[i]);
+		// TODO: Key press / release
+
+		// TODO: NOT WORKING
+		unsigned int key = usbkbd_parse_scancode(key_codes[i]);
+		kbd_push_ev(KEY_PRESS, key);
 	}
 	printf("\n");
@@ -267,12 +416,16 @@
 	//usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 
 	//    NULL);
-	printf("Calling usb_hid_boot_keyboard_input_report()...\n)");
-	usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL);
+	printf("Calling usb_hid_boot_keyboard_input_report() with size %d\n",
+	    actual_size);
+	//dump_buffer("bufffer: ", buffer, actual_size);
+	int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 
+	    NULL);
+	if (rc != EOK) {
+		printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
+	}
 }
 
 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
 {
-	return;
-	
 	int rc;
 	usb_handle_t handle;
@@ -292,10 +445,13 @@
 	};
 
+	printf("Polling keyboard...\n");
+
 	while (true) {
-		async_usleep(1000 * 1000);
+		async_usleep(1000 * 1000 * 2);
 		rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
 		    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
 
 		if (rc != EOK) {
+			printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
 			continue;
 		}
@@ -303,4 +459,5 @@
 		rc = usb_drv_async_wait_for(handle);
 		if (rc != EOK) {
+			printf("Error in usb_drv_async_wait_for(): %d\n", rc);
 			continue;
 		}
@@ -311,4 +468,5 @@
 		 */
 		if (actual_size == 0) {
+			printf("Keyboard returned NAK\n");
 			continue;
 		}
@@ -317,4 +475,5 @@
 		 * TODO: Process pressed keys.
 		 */
+		printf("Calling usbkbd_process_interrupt_in()\n");
 		usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
 	}
@@ -337,4 +496,8 @@
 	// initialize device (get and process descriptors, get address, etc.)
 	usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
+	if (kbd_dev == NULL) {
+		printf("Error while initializing device.\n");
+		return -1;
+	}
 
 	usbkbd_poll_keyboard(kbd_dev);
Index: uspace/lib/usb/src/hidparser.c
===================================================================
--- uspace/lib/usb/src/hidparser.c	(revision 2b9646335943ad9872daddeaffee9b749d2830c1)
+++ uspace/lib/usb/src/hidparser.c	(revision 3ee48f217f37deba9991dc929458dd9c73c0a7fb)
@@ -35,4 +35,5 @@
 #include <usb/classes/hidparser.h>
 #include <errno.h>
+#include <stdio.h>
 
 /** Parse HID report descriptor.
@@ -120,11 +121,11 @@
 	item.logical_max = 255;
 
-	if(size != 8){
-		return -1;
+	if (size != 8) {
+		return ERANGE;
 	}
 
 	uint8_t keys[6];
-	for(i=item.offset; i<item.count; i++) {
-		keys[i-2] = data[i];
+	for (i = 0; i < item.count; i++) {
+		keys[i] = data[i + item.offset];
 	}
 
