How do I detect an F1 keypress?

13 views
Skip to first unread message

Mark

unread,
Nov 30, 2021, 8:47:56 AM11/30/21
to fltk.general
At the moment I have this (using the rust bindings):
```rust
    main_window.handle(move |_, event| match event {
        fltk::enums::Event::KeyUp => {
            match fltk::app::event_key() {
                // TODO | F1
                fltk::enums::Key::Help => sender.send(WindowAction::Help),
                _ => {}
            }
            false
        }
        _ => false,
    });
```
But I can't figure out what I need to do to detect F1.

Albrecht Schlosser

unread,
Nov 30, 2021, 9:03:10 AM11/30/21
to fltkg...@googlegroups.com
I can't speak for the Rust bindings, but in C++ you would use 'FL_F+n'
for Fn where 'n' is a numeric value, hence F1 would be FL_F+1.

Key values are defined in FL/Enumerations.H, specifically here:
https://github.com/fltk/fltk/blob/36af6a57295a5f3c674134cab60dc644c96e97fa/FL/Enumerations.H#L477


Mark

unread,
Nov 30, 2021, 12:13:44 PM11/30/21
to fltk.general
You can't convert between enums (which is how the keys are defined in fltk-rs) and ints so I've reported it as a bug and asked the maintainer to add Key::F1 etc.

Thanks.

Bill Spitzak

unread,
Nov 30, 2021, 12:45:10 PM11/30/21
to fltkg...@googlegroups.com
Could Rust support some kind of inline function, like FL_F(1)? It would be useful to be able to convert from an integer to a function key number.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/6f851ee9-27ac-4abf-9315-f9a7f3268df3n%40googlegroups.com.

Mo_Al_

unread,
Nov 30, 2021, 1:34:33 PM11/30/21
to fltk.general
I've added function keys from F1 thru F12. I understand there are some keyboards with more function keys, so I've also added a const function (like C++ constexpr) to generate a function key. Key::fn_key(n), These can't be used in match statements since Rust disallows function calls in the match, however they can be defined beforehand and used in the match:

win.handle(|w, ev| match ev {
        Event::KeyUp => match app::event_key() {
            Key::F2 => {
                dbg!("F2");
                true
            }
            _ => false,
        },
        _ => false,
    });

using fn_key():

    const F12: Key = Key::fn_key(12); // the value can be inlined in the match

    win.handle(|w, ev| match ev {
        Event::KeyUp => match app::event_key() {
            F12 => {
                dbg!("F12");
                true
            }
            _ => false,
        },
        _ => false,
    });

Reply all
Reply to author
Forward
0 new messages