~eliasnaur/gio

1

Behaviour in key.Set for Key Events of Modifier Keys

Details
Message ID
<CAHe4cPmRCt3eggL6JRQ-ECDmx6QFqBdq9h-tbpmdQ4F+OhFB5w@mail.gmail.com>
DKIM signature
pass
Download raw message
Hi,

I noticed a slightly odd behaviour in key.Press. To capture the user
pressing and releasing the Ctrl key itself (not as a modifier), I would
assume I could use the filter:

    Ctrl

However on Windows I must instead use:

    Ctrl-Ctrl|Ctrl

The reason being that the key being pressed is detected as Ctrl, then
the modifiers are computed and Ctrl is detected as a modifier. Thus to
match a key press, "Ctrl-Ctrl" is needed, while to match a release
"Ctrl" is needed. The other modifiers like Shift behave similarly.

The behaviour, however, is platform dependent. On Unix the Ctrl key when
pressed is not considered to also be a modifier of itself so "Ctrl" as a
filter is sufficient. I haven't tried it on other platforms.

Is it worth changing this behaviour since it's a fairly rare case, and
the full filter "Ctrl-Ctrl|Ctrl" works on most platforms? If not, is it
worth adding it to a FAQ somewhere in case someone needs it? It took me
a while to dig through the code to figure out what's going on.

Cheers,

Jeff
Details
Message ID
<CAMAFT9USQD0xXaC_WhoL-7_TctOHCveQJc=COEPebd2Uzyxh9Q@mail.gmail.com>
In-Reply-To
<CAHe4cPmRCt3eggL6JRQ-ECDmx6QFqBdq9h-tbpmdQ4F+OhFB5w@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Tue, 3 May 2022 at 21:21, Jeff Williams <kanobe@gmail.com> wrote:
>
> I noticed a slightly odd behaviour in key.Press. To capture the user
> pressing and releasing the Ctrl key itself (not as a modifier), I would
> assume I could use the filter:
>
>     Ctrl
>
> However on Windows I must instead use:
>
>     Ctrl-Ctrl|Ctrl
>
> The reason being that the key being pressed is detected as Ctrl, then
> the modifiers are computed and Ctrl is detected as a modifier. Thus to
> match a key press, "Ctrl-Ctrl" is needed, while to match a release
> "Ctrl" is needed. The other modifiers like Shift behave similarly.
>
> The behaviour, however, is platform dependent. On Unix the Ctrl key when
> pressed is not considered to also be a modifier of itself so "Ctrl" as a
> filter is sufficient. I haven't tried it on other platforms.
>
> Is it worth changing this behaviour since it's a fairly rare case, and
> the full filter "Ctrl-Ctrl|Ctrl" works on most platforms? If not, is it
> worth adding it to a FAQ somewhere in case someone needs it? It took me
> a while to dig through the code to figure out what's going on.
>

Changing Gio's behaviour to report Ctrl using the filter "Ctrl" on
every platform sounds good to me.

Elias
Reply to thread Export thread (mbox)