~eliasnaur/gio

6 3

Detect key released

András Belicza
Details
Message ID
<CAP-HBqnpShtb0tSoiStNjrKyPoWBHp+Va4c8T-jSt5gpYkXyug@mail.gmail.com>
DKIM signature
pass
Download raw message
Is it possible to detect if a key (on the keyboard) is released?

I get key.Event and key.EditEvent when I press a key,
which will get repeated if the key is hold down,
but there is no event when I release the key.

For mouse, there are 2 events emitted (pointer.Event) with
Type=Press and Type=Release.

Thanks.
Details
Message ID
<C0F4P1MDCMBB.1JH45UWF2E55Y@toolbox>
In-Reply-To
<CAP-HBqnpShtb0tSoiStNjrKyPoWBHp+Va4c8T-jSt5gpYkXyug@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Thu Feb 6, 2020 at 14:23, András Belicza wrote:
> Is it possible to detect if a key (on the keyboard) is released?
>
> I get key.Event and key.EditEvent when I press a key,
> which will get repeated if the key is hold down,
> but there is no event when I release the key.
>
> For mouse, there are 2 events emitted (pointer.Event) with
> Type=Press and Type=Release.
>

Key release events haven't been implemented, partly because some platforms
(Android, iOS) do not report them, even for physical keyboards. They should
be easy to add, if a little tedious because events are per-platform.

Out of curiosity, what do you need key releases for?

-- elias
András Belicza
Details
Message ID
<CAP-HBqnd5pk8Uiby0KnReFiGB8GVk0QgsyAHB+Kr8groWHD61A@mail.gmail.com>
In-Reply-To
<C0F4P1MDCMBB.1JH45UWF2E55Y@toolbox> (view parent)
DKIM signature
pass
Download raw message
They might come handy in games where you want to control characters
while keys are pressed. E.g. move left as long as the Left key is
pressed, and stop when it's released.

On Thu, Feb 6, 2020 at 2:53 PM Elias Naur <mail@eliasnaur.com> wrote:
>
> On Thu Feb 6, 2020 at 14:23, András Belicza wrote:
> > Is it possible to detect if a key (on the keyboard) is released?
> >
> > I get key.Event and key.EditEvent when I press a key,
> > which will get repeated if the key is hold down,
> > but there is no event when I release the key.
> >
> > For mouse, there are 2 events emitted (pointer.Event) with
> > Type=Press and Type=Release.
> >
>
> Key release events haven't been implemented, partly because some platforms
> (Android, iOS) do not report them, even for physical keyboards. They should
> be easy to add, if a little tedious because events are per-platform.
>
> Out of curiosity, what do you need key releases for?
>
> -- elias
Details
Message ID
<CAE_4BPAJG3OO=AdRFVtkdKVjVdSqwJa=HB9XJwmtxB9tBObbbA@mail.gmail.com>
In-Reply-To
<C0F4P1MDCMBB.1JH45UWF2E55Y@toolbox> (view parent)
DKIM signature
missing
Download raw message
Key release notifications are used (for example) by Gmail's paged list
of emails.  You can hold down the "j" key to move the selection down,
but it stops when you get to the bottom of the page until you release
the key, and only moves to the next page (next email) when you press
"j" again.  Ditto using the "k" key to go up.

Disclaimer: I don't *know* that Gmail actually gets a "key release"
notification *per se*, but it certainly behaves as if it does.  It may
just detect that you have the key held down by the frequency and
timing of the key events, I dunno.  But certainly, if you wanted to
implement a similar behavior in Gio, a key release event would be
handy.

Come to think of it, I actually have a list in my own app, where going
down from the bottom entry takes you to the first entry (and vice
versa), where just such a behavior could be handy.

— Larry

On Thu, Feb 6, 2020 at 8:51 AM Elias Naur <mail@eliasnaur.com> wrote:
>
> On Thu Feb 6, 2020 at 14:23, András Belicza wrote:
> > Is it possible to detect if a key (on the keyboard) is released?
> >
> > I get key.Event and key.EditEvent when I press a key,
> > which will get repeated if the key is hold down,
> > but there is no event when I release the key.
> >
> > For mouse, there are 2 events emitted (pointer.Event) with
> > Type=Press and Type=Release.
> >
>
> Key release events haven't been implemented, partly because some platforms
> (Android, iOS) do not report them, even for physical keyboards. They should
> be easy to add, if a little tedious because events are per-platform.
>
> Out of curiosity, what do you need key releases for?
>
> -- elias
Details
Message ID
<C0F5RXCCML0G.3TLPJBZ2RMMIO@testmac>
In-Reply-To
<CAP-HBqnd5pk8Uiby0KnReFiGB8GVk0QgsyAHB+Kr8groWHD61A@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Thu Feb 6, 2020 at 3:03 PM, András Belicza wrote:
> They might come handy in games where you want to control characters
> while keys are pressed. E.g. move left as long as the Left key is
> pressed, and stop when it's released.
>

I see. I'm actually working on splitting out the rendering part of
Gio to make it easy to integrate with custom rendering, ala Dear ImGui.
Perhaps you could be interested in adding key release for the
platform of interest? Say for Windows, a good start is

	app/internal/window/os_window.go

Look for key.Event{...}

-- elias
András Belicza
Details
Message ID
<CAP-HBqnVq+EjzJWr0p3gA1Ts=sNq5ebF5cuNqY-KUjDqHAqQ3g@mail.gmail.com>
In-Reply-To
<C0F5RXCCML0G.3TLPJBZ2RMMIO@testmac> (view parent)
DKIM signature
pass
Download raw message
I don't use Windows but linux, and I don't find key.Event{} in
app/internal/window/os_x11.go.

On Thu, Feb 6, 2020 at 3:45 PM Elias Naur <mail@eliasnaur.com> wrote:
>
> On Thu Feb 6, 2020 at 3:03 PM, András Belicza wrote:
> > They might come handy in games where you want to control characters
> > while keys are pressed. E.g. move left as long as the Left key is
> > pressed, and stop when it's released.
> >
>
> I see. I'm actually working on splitting out the rendering part of
> Gio to make it easy to integrate with custom rendering, ala Dear ImGui.
> Perhaps you could be interested in adding key release for the
> platform of interest? Say for Windows, a good start is
>
>         app/internal/window/os_window.go
>
> Look for key.Event{...}
>
> -- elias
Details
Message ID
<C0F6TGOWOUJ7.OMF5N5KPWBRP@toolbox>
In-Reply-To
<CAP-HBqnVq+EjzJWr0p3gA1Ts=sNq5ebF5cuNqY-KUjDqHAqQ3g@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Thu Feb 6, 2020 at 16:11, András Belicza wrote:
> I don't use Windows but linux, and I don't find key.Event{} in
> app/internal/window/os_x11.go.
>

The relevant package for unix-compatible platforms is `xkb`.
See app/internal/xkb/xkb_unix.go.

-- elias