Detect if a certain key is pressed during a mouse click

35 views
Skip to first unread message

monocasual laboratories

unread,
Feb 15, 2022, 4:30:25 PM2/15/22
to fltk.general
Hi,

In my handle() method I'm trying to detect if a certain key (FL_Shift_L specifically) is being pressed during a mouse click. I'm aware of the existence of Fl::event_shift(), but it's too generic - I need to detect just the left shift. Also, the key might change in the future from FL_Shift_L to something else (say FL_Page_Down) so I'm looking for a more flexible approach. Any help?

Thanks in advance

pvrose

unread,
Feb 15, 2022, 4:54:22 PM2/15/22
to fltkg...@googlegroups.com

On 15 February 2022, at 21:30, monocasual laboratories <monoc...@gmail.com> wrote:

>Hi,
>
>In my handle() method I'm trying to detect if a certain key (FL_Shift_L specifically) is being pressed during a mouse click. I'm aware of the existence of Fl::event_shift(), but it's too generic - I need to detect just the left shift. Also, the key might change in the future from FL_Shift_L to something else (say FL_Page_Down) so I'm looking for a more flexible approach. Any help?

Hi "Monocausal",

You can detect key-up and key-down events on individual keys, including shift-L. Use this to check if your designated key is down on the mouse event.

Regards Phil.
>
>Thanks in advance
>
>--
>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/e06b2323-0fef-4399-b1fe-1fd0c4374817n%40googlegroups.com.

Ian MacArthur

unread,
Feb 16, 2022, 4:41:24 AM2/16/22
to fltk.general
It might also depend on what host you are on - particularly X11 can be a bit odd about delivering  events for modifier keys without an associated "main" key, so getting a "bare" Shift key from the X11 events may be unreliable (though IIRC that depends somewhat on X11 system and WM in use and etc...) 
You can get at the raw HID events or etc. on Linux, but that's a nightmare to work with in an app, so I'd not be keen on going that way...

If you look at the test/keyboard demo, you can see how it tracks the various key presses and perhaps extend from that sort of idea?


monocasual laboratories

unread,
Feb 19, 2022, 3:21:37 AM2/19/22
to fltk.general
Thank you all for the suggestions. I'll look into the keyboard demo and see what I can get from it. 

Giovanni

Matthias Melcher

unread,
Feb 19, 2022, 4:53:05 PM2/19/22
to fltk.general
You can check the status of any key using Fl::get_key(): https://www.fltk.org/doc-1.4/group__fl__events.html#gab7049319eed772c8a22cf2c0eb484a39 . Fl::event_state)( returns among other things a mask of modifier keys and mouse buttons that are currently pressed, https://www.fltk.org/doc-1.4/group__fl__events.html#gafa17a5b4d8d9163631c88142e60447ed, however, it does not differentiate between left and right shift key. Some of our supported platforms do not differentiate between left and right modifiers anyway.
Reply all
Reply to author
Forward
0 new messages