Fix numeric keyboard example program
examples/howto-remap-numpad-keyboard-keys.cxx: Substitute Fl::event_key() as well which is required for some input widgets - maybe only on some platforms (seemed to work on X11 but not on Wayland). Also: fix typos and whitespace.
This commit is contained in:
parent
c8112003ca
commit
829cac52c6
@ -1,4 +1,19 @@
|
|||||||
// vim: autoindent tabstop=8 shiftwidth=2 expandtab softtabstop=2
|
//
|
||||||
|
// Numeric keypad demo program for the Fast Light Tool Kit (FLTK).
|
||||||
|
//
|
||||||
|
// Copyright 1998-2024 by Bill Spitzak and others.
|
||||||
|
//
|
||||||
|
// This library is free software. Distribution and use rights are outlined in
|
||||||
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
|
// file is missing or damaged, see the license at:
|
||||||
|
//
|
||||||
|
// https://www.fltk.org/COPYING.php
|
||||||
|
//
|
||||||
|
// Please see the following page on how to report bugs and issues:
|
||||||
|
//
|
||||||
|
// https://www.fltk.org/bugs.php
|
||||||
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
// Demonstrate keyboard remapping: Force number pad to type numbers even if NumLock off
|
// Demonstrate keyboard remapping: Force number pad to type numbers even if NumLock off
|
||||||
//
|
//
|
||||||
@ -21,36 +36,22 @@
|
|||||||
//
|
//
|
||||||
// This demo based on fltk.general thread entitled "keyboard mapping", Aug 2019.
|
// This demo based on fltk.general thread entitled "keyboard mapping", Aug 2019.
|
||||||
//
|
//
|
||||||
// * * *
|
|
||||||
//
|
|
||||||
// Copyright 1998-2017 by Bill Spitzak and others.
|
|
||||||
//
|
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
|
||||||
// the file "COPYING" which should have been included with this file. If this
|
|
||||||
// file is missing or damaged, see the license at:
|
|
||||||
//
|
|
||||||
// https://www.fltk.org/COPYING.php
|
|
||||||
//
|
|
||||||
// Please see the following page on how to report bugs and issues:
|
|
||||||
//
|
|
||||||
// https://www.fltk.org/bugs.php
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Double_Window.H>
|
#include <FL/Fl_Double_Window.H>
|
||||||
#include <FL/Fl_Input.H>
|
#include <FL/Fl_Input.H>
|
||||||
#include <FL/Fl_Check_Button.H>
|
#include <FL/Fl_Check_Button.H>
|
||||||
|
|
||||||
//
|
|
||||||
Fl_Check_Button *G_checkbut = 0;
|
Fl_Check_Button *G_checkbut = 0;
|
||||||
|
|
||||||
// Global event handler: FLTK calls this after event translation. It's up to us
|
// Global event handler: FLTK calls this after event translation. It's up to us
|
||||||
// to call Fl::handle_(e,w) to actually deliver the event to the widgets. If we
|
// to call Fl::handle_(e,w) to actually deliver the event to the widgets. If we
|
||||||
// don't and just return, the event will be dropped. See docs for more.
|
// don't and just return, the event will be dropped. See docs for more.
|
||||||
//
|
|
||||||
int MyHandler(int e, Fl_Window *w) {
|
int MyHandler(int e, Fl_Window *w) {
|
||||||
// Remapping disabled? Early exit..
|
// Remapping disabled? Early exit..
|
||||||
if ( G_checkbut->value() == 0 ) return Fl::handle_(e, w);
|
if (G_checkbut->value() == 0)
|
||||||
|
return Fl::handle_(e, w);
|
||||||
// Keyboard key pressed? See if we should remap..
|
// Keyboard key pressed? See if we should remap..
|
||||||
if (e == FL_KEYDOWN || e == FL_KEYUP) {
|
if (e == FL_KEYDOWN || e == FL_KEYUP) {
|
||||||
// Get FLTK keycode /before/ NumLock state is applied (see above DESCRIPTION)
|
// Get FLTK keycode /before/ NumLock state is applied (see above DESCRIPTION)
|
||||||
@ -61,6 +62,7 @@ int MyHandler(int e, Fl_Window *w) {
|
|||||||
buf[1] = 0; // terminate string (for safety)
|
buf[1] = 0; // terminate string (for safety)
|
||||||
Fl::e_text = buf; // point to our static buffer
|
Fl::e_text = buf; // point to our static buffer
|
||||||
Fl::e_length = 1; // only first char relevant
|
Fl::e_length = 1; // only first char relevant
|
||||||
|
Fl::e_keysym = keycode; // note: some input widgets require this too
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Fl::handle_(e, w); // let FLTK deliver event to widgets
|
return Fl::handle_(e, w); // let FLTK deliver event to widgets
|
||||||
@ -78,7 +80,7 @@ int main(int argc, char *argv[]) {
|
|||||||
win->end();
|
win->end();
|
||||||
win->resizable(win);
|
win->resizable(win);
|
||||||
win->show(argc, argv);
|
win->show(argc, argv);
|
||||||
win->tooltip("Turn NumLock OFF, then type into Input:\nusing numeric keypadt to test translation");
|
win->tooltip("Turn NumLock OFF, then type into Input:\nusing numeric keypad to test translation");
|
||||||
// Set up our event handler to manage events
|
// Set up our event handler to manage events
|
||||||
Fl::event_dispatch(MyHandler);
|
Fl::event_dispatch(MyHandler);
|
||||||
return(Fl::run());
|
return(Fl::run());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user