[master] 986a8b3 - Fix keyboard demo international keyboards

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 986a8b3 - Fix keyboard demo international keyboards "Albrecht Schlosser" 04:32 Jun 11 top right image
 
commit 986a8b33a2b5e503dd36ddbc8283d489ebbd9290
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Fri Jun 11 13:25:31 2021 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Fri Jun 11 13:25:31 2021 +0200

    Fix keyboard demo international keyboards
    
    Fl::event_key() display needs to be converted to UTF-8 for keycodes
    outside the ASCII range (0xa0 - 0xff). Such keycodes can be found
    on international keyboards.

 test/keyboard.cxx | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git test/keyboard.cxx test/keyboard.cxx
index e28a302..feb896c 100644
--- test/keyboard.cxx
+++ test/keyboard.cxx
@@ -1,7 +1,7 @@
 //
-
+// Keyboard/event test program for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2021 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
@@ -15,8 +15,6 @@
 //
 
 //
-// Keyboard/event test program for the Fast Light Tool Kit (FLTK).
-//
 // Continuously display FLTK's event state.
 //
 // Known bugs:
@@ -33,10 +31,8 @@
 //
 
 #include "keyboard_ui.h"
-
 #include <string.h>
 
-
 // these are used to identify which buttons are which:
 void key_cb(Fl_Button*, void*) {}
 void shift_cb(Fl_Button*, void*) {}
@@ -48,8 +44,7 @@ int handle(int e) {
 }
 
 int MyWindow::handle(int msg) {
-  if (msg==FL_MOUSEWHEEL)
-  {
+  if (msg==FL_MOUSEWHEEL) {
     roller_x->value( roller_x->value() + Fl::e_dx * roller_x->step() );
     roller_y->value( roller_y->value() + Fl::e_dy * roller_y->step() );
     return 1;
@@ -123,8 +118,13 @@ int main(int argc, char** argv) {
     int k = Fl::event_key();
     if (!k)
       keyname = "0";
-    else if (k < 256) {
+    else if (k < 128) { // ASCII
       sprintf(buffer, "'%c'", k);
+    } else if (k >= 0xa0 && k <= 0xff) { // ISO-8859-1 (international keyboards)
+      char key[8];
+      int kl = fl_utf8encode((unsigned)k, key);
+      key[kl] = '\0';
+      sprintf(buffer, "'%s'", key);
     } else if (k > FL_F && k <= FL_F_Last) {
       sprintf(buffer, "FL_F+%d", k - FL_F);
     } else if (k >= FL_KP && k <= FL_KP_Last) {
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2022 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.