detect keydown function

28 views
Skip to first unread message

danielc...@gmail.com

unread,
Apr 20, 2022, 3:32:09 PM4/20/22
to fltk.general
Hi, is there a function to detect if a key is pressed?
I know for Fl::event_alt () but it dont works on linux it works on windows, tested.

Thanks

danielc...@gmail.com

unread,
Apr 20, 2022, 5:27:09 PM4/20/22
to fltk.general
I correct, the Fl::event_alt () works on linux, windows detects altgr as alt.
What is the  Fl::event_alt gr () keyisdown function?

imm

unread,
Apr 20, 2022, 5:46:06 PM4/20/22
to General FLTK
On Wed, 20 Apr 2022, 22:27 danielchanfana wrote:
I correct, the Fl::event_alt () works on linux, windows detects altgr as alt.
What is the  Fl::event_alt gr () keyisdown function?

Delivery of modifier keys under X11 can be a bit fragile on a lot of platforms - the server may only deliver them along with the key they modify, so "bare" modifier keys can be awkward to detect reliably at times.

Similarly, distinguishing between Alt and AltGr may depend on what the server / keymap / etc decided to send...

If you really need to see the raw key events you may need to step outside the fltk/X11 APIs and grab the raw data for yourself.

What is it you are actually trying to achieve, maybe somebody knows a good way to get there?

--
Ian
From my Fairphone FP3

danielc...@gmail.com

unread,
Apr 20, 2022, 6:02:21 PM4/20/22
to fltk.general
Ok I just wanted to use shortcut keys with altgr, I just switch to the other hand.
It would be nice to have other options in linux for altgr.
Thanks

Albrecht Schlosser

unread,
Apr 21, 2022, 8:00:37 AM4/21/22
to fltkg...@googlegroups.com
You can use test/keyboard.cxx to find out what FLTK reports in Fl::event_key(). On my system with a German keyboard (which may matter [1]) the keyboard demo reports:

Alt: FL_Alt_L

AltGr: 0xfe03

There's obviously no "translation" to a FLTK keyname for AltGr.

I don't know how this can be used as a shortcut though and I don't have more time to investigate right now. You may want to look at Fl::event_state() to in an event handler on an FL_KEYDOWN event, maybe.

Another way to get to the raw "keycodes" and "keysyms" is the Unix/Linux tool 'xev'. On my system it reports for Alt and AltGr respectively:

KeyPress event, serial 23, synthetic NO, window 0x8000003,
    root 0x7a3, subw 0x0, time 222203684, (350,-16), root:(401,47),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 23, synthetic NO, window 0x8000003,
    root 0x7a3, subw 0x0, time 222325738, (254,-17), root:(305,46),
    state 0x80, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

To run this test with 'xev -id <id>' I first used 'xwininfo' and clicked on the FLTK keyboard demo window to get its "Window id".

HTH

[1] IIRC the "keysyms" reported for different keyboard layouts, particularly for special keys like AltGr may differ on different keyboard layouts but I'm not sure if this indeed affects the AltGr key.

danielc...@gmail.com

unread,
Apr 21, 2022, 2:02:50 PM4/21/22
to fltk.general
Thanks but I simply changed to the left alt, but now windows make a ding when I press with other letter.
Anyway to supress that ding?
Thanks

Ian MacArthur

unread,
Apr 21, 2022, 3:09:00 PM4/21/22
to Fltk General
On 21 Apr 2022, at 19:02, danielchanfana wrote:
>
> Thanks but I simply changed to the left alt, but now windows make a ding when I press with other letter.
> Anyway to supress that ding?

From fltk? No, I do not think so.

Though Alt-blah key combinations are (at least in my experience anyway) silent, unless you are trying to use a combination that the OS or WM want for themselves...?

Remember that the key events go a lot of places before they get to fltk and your app - notably to the OS itself (which has a good look for events and key-combinations it cares about as “special”) and then to the window manager (which also has a good look for “special” key combos) before it gets anywhere near you code...

Most of the current “systems", and Windows is bad for this, have a heap of key-combos already reserved that they use for particular operations, and you pretty much can not use those combos for your own purposes; it can be a real nuisance.

What key combinations were you using? Are they ones that Windows already has a special use for?

>
> Em quinta-feira, 21 de abril de 2022 às 13:00:37 UTC+1, Albrecht Schlosser escreveu:
>
> You can use test/keyboard.cxx to find out what FLTK reports in Fl::event_key(). On my system with a German keyboard (which may matter [1]) the keyboard demo reports:
>
> Alt: FL_Alt_L
>
> AltGr: 0xfe03
>
> There's obviously no "translation" to a FLTK keyname for AltGr.


On “some” systems (and this probably depends on the keymap, locale, who-knows-what-else) I have seen the Right-Alt (AltGr) return as (Alt + Ctrl), so that might be a thing?
Do not know...



danielc...@gmail.com

unread,
Apr 21, 2022, 5:28:42 PM4/21/22
to fltk.general
I'm using alt+z and alt+x, its strange the ding because it only does when the text widget is focused, not anywhere else in the app.

imm

unread,
Apr 22, 2022, 9:23:03 AM4/22/22
to General FLTK
On Thu, 21 Apr 2022, 22:28 danielchanfana wrote:
I'm using alt+z and alt+x, its strange the ding because it only does when the text widget is focused, not anywhere else in the app.

Yes, that does sound a bit odd: I'm not sure - does anyone know if Alt-x & Alt-z have some "well known" meaning?

Ctrl-x & Ctrl-z do, of course, but not sure about those two!

lifeatt...@gmail.com

unread,
Apr 28, 2022, 2:18:13 PM4/28/22
to fltk.general
Alt+X is a common Windows key combo "most often used to display the Unicode character code of a character". I thought it was MS-Word only tho ...

Alt+Z apparently shows the favorites menu in Internet Explorer. I don't know if that has been propagated to MS-Edge.
 
Yes, that does sound a bit odd: I'm not sure - does anyone know if Alt-x & Alt-z have some "well known" meaning?

This looks like they are program-specific, not "general windows" keys.
 
Reply all
Reply to author
Forward
0 new messages