2
// "$Id: keyboard.cxx 9303 2012-03-26 16:54:54Z manolo $"
6
// Copyright 1998-2010 by Bill Spitzak and others.
8
// This library is free software. Distribution and use rights are outlined in
9
// the file "COPYING" which should have been included with this file. If this
10
// file is missing or damaged, see the license at:
12
// http://www.fltk.org/COPYING.php
14
// Please report all bugs and problems on the following page:
16
// http://www.fltk.org/str.php
20
// Keyboard/event test program for the Fast Light Tool Kit (FLTK).
22
// Continuously display FLTK's event state.
26
// X insists on reporting the state *before* the shift key was
27
// pressed, rather than after, on shift key events. I fixed this for
28
// the mouse buttons, but it did not seem worth it for shift.
30
// X servers do not agree about any shift flags after except shift, ctrl,
31
// lock, and alt. They may also not agree about the symbols for the extra
32
// keys Micro$oft put on the keyboard.
34
// On IRIX the backslash key does not work. A bug in XKeysymToKeycode?
36
#include "../include/keyboard.h"
37
#include "../fltk/keyboard-ui.h"
42
// these are used to identify which buttons are which:
43
void key_cb(Fl_Button*, void*) {}
44
void shift_cb(Fl_Button*, void*) {}
45
void wheel_cb(Fl_Dial*, void*) {}
47
// this is used to stop Esc from exiting the program:
49
return (e == FL_SHORTCUT); // eat all keystrokes
52
int MyWindow::handle(int msg) {
53
if (msg==FL_MOUSEWHEEL)
55
roller_x->value( roller_x->value() + Fl::e_dx * roller_x->step() );
56
roller_y->value( roller_y->value() + Fl::e_dy * roller_y->step() );
62
struct keycode_table{int n; const char* text;} table[] = {
63
{FL_Escape, "Escape"},
64
{FL_BackSpace, "BackSpace"},
66
{FL_Iso_Key, "Iso_Key"},
69
{FL_Scroll_Lock, "Scroll_Lock"},
71
{FL_Insert, "Insert"},
73
{FL_Page_Up, "Page_Up"},
74
{FL_Delete, "Delete"},
76
{FL_Page_Down, "Page_Down"},
81
{FL_Shift_L, "Shift"},
82
{FL_Shift_R, "Shift"},
83
{FL_Control_L, "Control"},
84
{FL_Control_R, "Control"},
85
{FL_Caps_Lock, "Caps_Lock"},
92
{FL_Num_Lock, "Num_Lock"},
93
{FL_KP_Enter, "Enter"},
94
{FL_Volume_Down, "XF86AudioLowerVolume"},
95
{FL_Volume_Up, "XF86AudioRaiseVolume"},
96
{FL_Volume_Mute, "XF86AudioMute"},
97
{FL_Media_Play,"XF86AudioPause"},
98
{FL_Media_Stop,"XF86AudioStop"},
99
{FL_Media_Prev,"XF86AudioPrev"},
100
{FL_Media_Next,"XF86AudioNext"},
101
{FL_Home_Page,"XF86HomePage"},
102
{FL_Mail,"XF86Mail"},
103
{FL_Search,"XF86Search"},
104
{FL_Back,"XF86Back"},
105
{FL_Forward,"XF86Forward"},
106
{FL_Sleep,"XF86Standby"},
107
{FL_Favorites,"XF86Favorites"}
110
// {FL_Stop,"XF86??"},
111
// {FL_Refresh,"XF86Refresh???"}
112
int main(int argc, char** argv) {
113
Fl::add_handler(handle);
114
MyWindow *window = make_window();
115
window->show(argc,argv);
119
// update all the buttons with the current key and shift state:
120
for (int i = 0; i < window->children(); i++) {
121
Fl_Widget* b = window->child(i);
122
if (b->callback() == (Fl_Callback*)key_cb) {
123
int i = b->argument();
124
if (!i) i = b->label()[0];
125
Fl_Button *btn = ((Fl_Button*)b);
126
int state = Fl::event_key(i);
127
if (btn->value()!=state)
129
} else if (b->callback() == (Fl_Callback*)shift_cb) {
130
int i = b->argument();
131
Fl_Button *btn = ((Fl_Button*)b);
132
int state = Fl::event_state(i);
133
if (btn->value()!=state)
138
// figure out the keyname:
140
const char *keyname = buffer;
141
int k = Fl::event_key();
145
sprintf(buffer, "'%c'", k);
146
} else if (k > FL_F && k <= FL_F_Last) {
147
sprintf(buffer, "FL_F+%d", k - FL_F);
148
} else if (k >= FL_KP && k <= FL_KP_Last) {
149
sprintf(buffer, "FL_KP+'%c'", k-FL_KP);
150
} else if (k >= FL_Button && k <= FL_Button+7) {
151
sprintf(buffer, "FL_Button+%d", k-FL_Button);
153
sprintf(buffer, "0x%04x", k);
154
for (int i = 0; i < int(sizeof(table)/sizeof(*table)); i++)
155
if (table[i].n == k) {keyname = table[i].text; break;}
157
if (strcmp(key_output->value(), keyname))
158
key_output->value(keyname);
160
str = Fl::event_text();
161
if (strcmp(text_output->value(), str))
162
text_output->value(str);
168
// End of "$Id: keyboard.cxx 9303 2012-03-26 16:54:54Z manolo $".