15818
|
1 #include <gnt.h>
|
|
2 #include <gntbox.h>
|
|
3 #include <gntentry.h>
|
|
4 #include <gntlabel.h>
|
|
5
|
|
6 static gboolean
|
|
7 print_keycode(GntEntry *entry, const char *text, gpointer null)
|
|
8 {
|
|
9 char *s = g_strdup_printf("%s ", text);
|
|
10 gnt_entry_set_text(entry, s);
|
|
11 g_free(s);
|
|
12 if (text[0] == 27)
|
|
13 {
|
|
14 if (strncmp(text + 1, "[M ", 3) == 0)
|
|
15 {
|
|
16 int x = (unsigned)text[4];
|
|
17 int y = (unsigned)text[5];
|
|
18 if (x < 0) x += 256;
|
|
19 if (y < 0) y += 256;
|
|
20 x -= 33;
|
|
21 y -= 33;
|
|
22 s = g_strdup_printf("ldown %d %d", x, y);
|
|
23 gnt_entry_set_text(entry, s);
|
|
24 g_free(s);
|
|
25 }
|
|
26 else if (strncmp(text + 1, "[M#", 3) == 0)
|
|
27 gnt_entry_set_text(entry, "up");
|
|
28 else
|
|
29 return FALSE;
|
|
30 return TRUE;
|
|
31 }
|
|
32 else
|
|
33 return TRUE;
|
|
34 }
|
|
35
|
|
36 int main()
|
|
37 {
|
|
38 GntWidget *window, *entry;
|
|
39
|
|
40 gnt_init();
|
|
41
|
|
42 freopen(".error", "w", stderr);
|
|
43
|
|
44 window = gnt_hbox_new(FALSE);
|
|
45 gnt_box_set_toplevel(GNT_BOX(window), TRUE);
|
|
46
|
|
47 gnt_box_add_widget(GNT_BOX(window), gnt_label_new("Press any key: "));
|
|
48
|
|
49 entry = gnt_entry_new(NULL);
|
|
50 gnt_box_add_widget(GNT_BOX(window), entry);
|
|
51 g_signal_connect(G_OBJECT(entry), "key_pressed", G_CALLBACK(print_keycode), NULL);
|
|
52
|
|
53 gnt_widget_set_position(window, getmaxx(stdscr) / 2 - 12, getmaxy(stdscr) / 2 - 3);
|
|
54 gnt_widget_show(window);
|
|
55
|
|
56 gnt_main();
|
|
57 gnt_quit();
|
|
58 return 0;
|
|
59 }
|
|
60
|