Implement she::is_key_pressed() on Win32 for the Skia port

This commit is contained in:
David Capello 2015-05-19 15:34:47 -03:00
parent 20f532ffe8
commit 189ee56c4c
2 changed files with 33 additions and 2 deletions

View File

@ -34,11 +34,12 @@ void error_message(const char* msg)
// TODO
}
#ifndef _WIN32
bool is_key_pressed(KeyScancode scancode)
{
// TODO
return false;
return false; // Do nothing
}
#endif
void clear_keyboard_buffer()
{

View File

@ -294,4 +294,34 @@ KeyScancode win32vk_to_scancode(int vk) {
return keymap[vk];
}
static int scancode_to_win32vk(KeyScancode scancode) {
static int initialized = false;
static int keymap[kKeyScancodes];
if (!initialized) {
initialized = true;
for (int i=0; i<kKeyScancodes; ++i)
keymap[i] = 0;
for (int vk=0; vk<256; ++vk) {
KeyScancode sc = win32vk_to_scancode(vk);
if (sc != kKeyNil)
keymap[sc] = vk;
}
}
if (scancode < kKeyNil || scancode > kKeyScancodes)
scancode = kKeyNil;
return keymap[scancode];
}
bool is_key_pressed(KeyScancode scancode)
{
int vk = scancode_to_win32vk(scancode);
if (vk)
return (GetKeyState(vk) & 0xf000 ? true: false);
else
return false;
}
} // namespace she