Skip to content

Commit

Permalink
implement keyup/keydown and non-repeating keydown for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbb committed Nov 13, 2009
1 parent f3f5d51 commit 4ab1424
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions shoes/app.c
Expand Up @@ -435,6 +435,7 @@ shoes_app_wheel(shoes_app *app, ID dir, int x, int y)
shoes_code
shoes_app_keydown(shoes_app *app, VALUE key)
{
app->pressedkey = key;
if (!RTEST(rb_hash_aref(app->keypresses, key))) {
rb_hash_aset(app->keypresses, key, Qtrue);
shoes_canvas_send_keydown(app->canvas, key);
Expand Down
1 change: 1 addition & 0 deletions shoes/app.h
Expand Up @@ -62,6 +62,7 @@ typedef struct _shoes_app {
VALUE self;
VALUE canvas;
VALUE keypresses;
VALUE pressedkey;
VALUE nestslot;
VALUE nesting;
VALUE extras;
Expand Down
8 changes: 8 additions & 0 deletions shoes/native/windows.c
Expand Up @@ -202,6 +202,7 @@ void shoes_native_remove_item(SHOES_SLOT_OS *slot, VALUE item, char c)
ScreenToClient(canvas->app->slot->window, &p); \

#define KEY_SYM(sym) shoes_app_keypress(app, ID2SYM(rb_intern("" # sym)))
#define KEY_SYM2(sym) shoes_app_keydown(app, ID2SYM(rb_intern("" # sym)))
#define KEYPRESS(name, sym) \
else if (w == VK_##name) { \
VALUE v = ID2SYM(rb_intern("" # sym)); \
Expand All @@ -212,6 +213,7 @@ void shoes_native_remove_item(SHOES_SLOT_OS *slot, VALUE item, char c)
if (app->os.ctrlkey) \
KEY_STATE(control); \
shoes_app_keypress(app, v); \
shoes_app_keydown(app, v); \
}

static void
Expand Down Expand Up @@ -562,14 +564,17 @@ shoes_app_win32proc(
{
case 0x08:
KEY_SYM(backspace);
KEY_SYM2(backspace);
break;

case 0x09:
KEY_SYM(tab);
KEY_SYM2(tab);
break;

case 0x0D:
shoes_app_keypress(app, rb_str_new2("\n"));
shoes_app_keydown(app, rb_str_new2("\n"));
break;

default:
Expand All @@ -581,6 +586,7 @@ shoes_app_win32proc(
str[len] = '\0';
v = rb_str_new(str, len);
shoes_app_keypress(app, v);
shoes_app_keydown(app, v);
}
}
break;
Expand Down Expand Up @@ -643,12 +649,14 @@ shoes_app_win32proc(
if (app->os.altkey) {
KEY_STATE(alt);
shoes_app_keypress(app, v);
shoes_app_keydown(app, v);
}
}
break;

case WM_SYSKEYUP:
case WM_KEYUP:
shoes_app_keyup(app, app->pressedkey);
if (w == VK_CONTROL)
app->os.ctrlkey = false;
else if (w == VK_MENU)
Expand Down

0 comments on commit 4ab1424

Please sign in to comment.