Almost working keyboard input. One can now select menu items, though it seems to miss 2/3 of the key presses.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39110 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2010-10-24 02:06:30 +00:00
parent 85cf9e37d6
commit 6fff309da9
2 changed files with 76 additions and 14 deletions
+69 -14
View File
@@ -39,6 +39,9 @@ class KeyboardDevice : public ExecDevice {
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
int WaitForKey();
status_t ReadEvent(struct InputEvent *event);
protected: protected:
}; };
@@ -144,27 +147,40 @@ KeyboardDevice::Open()
} }
status_t
KeyboardDevice::ReadEvent(struct InputEvent *event)
{
fIOStdReq->io_Command = KBD_READEVENT;
fIOStdReq->io_Flags = IOF_QUICK;
fIOStdReq->io_Length = sizeof(struct InputEvent);
fIOStdReq->io_Data = event;
status_t err = Do();
if (err < B_OK)
return err;
/*
dprintf("key: class %d sclass %d code %d 0x%02x qual 0x%04x\n",
event->ie_Class, event->ie_SubClass,
event->ie_Code, event->ie_Code, event->ie_Qualifier);
*/
return B_OK;
}
ssize_t ssize_t
KeyboardDevice::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) KeyboardDevice::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
{ {
struct InputEvent event; struct InputEvent event;
ssize_t actual; ssize_t actual;
status_t err;
do { do {
fIOStdReq->io_Command = KBD_READEVENT; err = ReadEvent(&event);
fIOStdReq->io_Flags = IOF_QUICK;
fIOStdReq->io_Length = sizeof(event);
fIOStdReq->io_Data = &event;
status_t err = Do();
if (err < B_OK) if (err < B_OK)
return err; return err;
} while (event.ie_Code > IECODE_UP_PREFIX); } while (event.ie_Code > IECODE_UP_PREFIX);
dprintf("key: class %d sclass %d code %d qual 0x%04x\n", event.ie_Class, event.ie_SubClass,
event.ie_Code, event.ie_Qualifier);
actual = MapRawKey(&event, (char *)buffer, bufferSize, NULL); actual = MapRawKey(&event, (char *)buffer, bufferSize, NULL);
dprintf("%s actual %d\n", __FUNCTION__, actual); //dprintf("%s actual %d\n", __FUNCTION__, actual);
if (actual > 0) { if (actual > 0) {
return actual; return actual;
} }
@@ -172,6 +188,47 @@ KeyboardDevice::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
} }
int
KeyboardDevice::WaitForKey()
{
struct InputEvent event;
char ascii;
ssize_t actual;
status_t err;
do {
err = ReadEvent(&event);
if (err < B_OK)
return err;
} while (event.ie_Code < IECODE_UP_PREFIX);
event.ie_Code &= ~IECODE_UP_PREFIX;
switch (event.ie_Code) {
case IECODE_KEY_UP:
return TEXT_CONSOLE_KEY_UP;
case IECODE_KEY_DOWN:
return TEXT_CONSOLE_KEY_DOWN;
case IECODE_KEY_LEFT:
return TEXT_CONSOLE_KEY_LEFT;
case IECODE_KEY_RIGHT:
return TEXT_CONSOLE_KEY_RIGHT;
case IECODE_KEY_PAGE_UP:
return TEXT_CONSOLE_KEY_PAGE_UP;
case IECODE_KEY_PAGE_DOWN:
return TEXT_CONSOLE_KEY_PAGE_DOWN;
default:
break;
}
actual = MapRawKey(&event, &ascii, 1, NULL);
//dprintf("%s actual %d\n", __FUNCTION__, actual);
if (actual > 0)
return ascii;
return TEXT_CONSOLE_NO_KEY;
}
ssize_t ssize_t
KeyboardDevice::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) KeyboardDevice::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize)
{ {
@@ -314,10 +371,8 @@ console_set_color(int32 foreground, int32 background)
int int
console_wait_for_key(void) console_wait_for_key(void)
{ {
//TODO int key = sInput.WaitForKey();
char key; //dprintf("k: %08x '%c'\n", key, key);
sInput.Read(&key, 1); return key;
dprintf("k: %02x '%c'\n", key, key);
return 0;
} }
@@ -1389,6 +1389,13 @@ struct InputEvent {
#define IECODE_UP_PREFIX 0x80 #define IECODE_UP_PREFIX 0x80
#define IECODE_KEY_UP 0x4c
#define IECODE_KEY_DOWN 0x4d
#define IECODE_KEY_LEFT 0x4f
#define IECODE_KEY_RIGHT 0x4e
#define IECODE_KEY_PAGE_UP 0x67
#define IECODE_KEY_PAGE_DOWN 0x66
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif