# Help me gather keystrokes and mouse events for varied platforms

**URL:** <https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307>\
**Category:** General\
**Tags:** drracket\
**Created:** [November 29, 2021, 8:54pm UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307 "2021-11-29T20:54:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [November 29, 2021, 8:54pm UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/1 "2021-11-29T20:54:18Z")

</div>

If you have a couple of minutes to spare (it shouldn't take you more than 5min in total), it would be great if you could help me gather accurate `key-event%` and `mouse-event%` for different platforms.

To do so:

1. `raco pkg install racket-paint` (which contains an experimental event listener. The paint program itself is irrelevant.)
2. `racket -l- racket-paint/event-listener --no-erase --mouse-state --system-info`
3. Type exactly the following sequence of keys (don't use the mouse wheel):

- `a`, `c:a`, `s:a`, `c:s:a`, `cmd:a`, `cmd:c:s:a`  
(where `c:` is the control key, `s:` is shift, and `a` is just `a`)
- `return`, `c:return`, `s:return`, `c:s:return`, `cmd:return`, `cmd:c:s:return`  
where `return` is the return key.
- `mleft`, `c:mleft`, `s:mleft`, `c:s:mleft`, `cmd:mleft`, `cmd:c:s:mleft`  
(where `mleft` = mouse left)  
Instead of `cmd` you can choose a modifier of your choice (caps, rshift, ...), just let me know which you tried.

1. Click `Copy`, then paste into a file editor.
2. Send me the results somehow: in this thread within a `[details]` block, in a private message on slack, in a email, pastebin, your choice.

Note that at the top there is some information that's specific to your machine. If for some reason you are not comfortable sharing these details, you can erase some of them, but I'd need at least the platform.

Thank you very much!

---

<div class="post-metadata">

**Author:** ![SamPhillips](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samphillips/32/15_2.png) [@SamPhillips](https://racket.discourse.group/u/SamPhillips)\
**Post date:** [November 29, 2021, 11:17pm UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/2 "2021-11-29T23:17:45Z")

</div>

~~What if your keyboard doesn't have a `cmd` key?~~

Apparently I cannot read...

---

<div class="post-metadata">

**Author:** ![marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@marc](https://racket.discourse.group/u/marc)\
**Post date:** [November 30, 2021, 8:47am UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/3 "2021-11-30T08:47:21Z")

</div>

Sent you my keystrokes. Out of curiosity, what is it for?

---

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [November 30, 2021, 9:37am UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/4 "2021-11-30T09:37:00Z")

</div>

Thanks Marc!

I've had a number of issues with keybindings in DrRacket and elsewhere, and I've observed some discrepancies depending on the platforms and versions.

For example, for some mac users (but not all), no modifier is recorded with a mouse event. Sometimes it's recorded by `(get-mouse-state)` but not by the mouse event itself, but not always. Also, GTK is inconsistent with when modifiers are considered up and down. I'll share here the results of my findings of course.

So I'm gathering some information to try to pin down the issues and see if anything can be done.

I'm also working on an alternative way to make keybinding actually work for all platforms: Instead of handcrafting the expected mouse events and trying to be smart about the various platforms (which seems hard, annoying, error-prone and varying over time and OS versions), the idea is simply to ask the user to perform the desired key or mouse event and record it. (Emacs does this.) The event listener is a means to make this easy for the user.

The (unstable) racket-paint program is a test-bed for this. If you run `racket -l racket-paint`, you'll see a keymap menu that allows to customize all keybindings with the event-listener. Ctl-left-click on a button also lets you rebind the default shortcut to a button. But it's still WIP.

---

<div class="post-metadata">

**Author:** ![marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@marc](https://racket.discourse.group/u/marc)\
**Post date:** [November 30, 2021, 9:40am UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/5 "2021-11-30T09:40:32Z")

</div>

Very nice, thanks for putting the work in to do this. Sounds like a really important, useful, and boring task.

And yes, the application crashed for me at some point.

---

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [November 30, 2021, 9:44am UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/6 "2021-11-30T09:44:42Z")

</div>

> [@marc](#):
>
> And yes, the application crashed for me at some point.

Crashes shouldn't happen 🙂 If you still have the log or if it happens again, please file an issue [here](https://github.com/Metaxal/racket-paint/issues).

---

<div class="post-metadata">

**Author:** ![marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@marc](https://racket.discourse.group/u/marc)\
**Post date:** [November 30, 2021, 10:27am UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/7 "2021-11-30T10:27:29Z")

</div>

No, I don't unfortunately. I'll run it again at some point and see if it happens again (it happened while sitting around doing nothing).

---

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [January 5, 2022, 3:36pm UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/8 "2022-01-05T15:36:10Z")

</div>

Thank you everyone for sending me your reports, this has been quite helpful. I found a few issues with `mouse-event%`s, in particular on Mac. This issue gives more details:

> <https://github.com/racket/gui/issues/255>
>
> Following the results gathered from https://racket.discourse.group/t/help-me-gat…her-keystrokes-and-mouse-events-for-varied-platforms/307/7
> 
> On \*\*Mac\*\*, there are several issues:
> \* \`control\` isn't reported in the \`mouse-event%\`, while it is reported by \`get-mouse-state\`.
> \* get-mouse-state reports \`left\` button instead of \`right\` or \`middle\`
> Example of such discrepancies:
> \* mouse-event%: \`right:shift:meta:right-down\`
> get-mouse-state: \`(914 602 left shift meta control)\`
> \* mouse-event%: \`right:right-down\`
> get-mouse-state: \`(614 435 left control)\`
> 
> \* Some Mac users reported that modifiers are not picked at all with mouse events
> 
> On \*\*Windows\*\*, things are mostly ok except that \`meta\` or \`alt\` are not always reported in the mouse-event%. Otherwise, the event also reports \`meta\` while the state reports \`alt\`.
> Example:
> \* mouse-event%: \`control:shift:left-up\`
> get-mouse-state: \`(1878 456 shift control alt)\`
> 
> On \*\*Unix\*\*, the only issue I found is that the mouse-event% reports \`meta\` while the state reports \`alt\`.
> 
> 
> Unfortunately I don't own a Mac or a Windows machine (only a Linux) so I can't really attempt to debug this. However, one can easily try it out with this:
> \`\`\`shell
> raco pkg install racket-paint
> racket -l- racket-paint/event-listener --mouse-state
> \`\`\`

---

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [April 9, 2022, 12:45pm UTC](https://racket.discourse.group/t/help-me-gather-keystrokes-and-mouse-events-for-varied-platforms/307/9 "2022-04-09T12:45:01Z")

</div>

Here's another keybinding issue in DrRacket:

My keyboard has several X layout groups, so that when I press Caps-Lock it goes to the second layout group.

In DrRacket, if I press **Alt-t** (keycode 44 per `xev`, keysym 0x74 "t") in the first layout, it drops down the Tabs menu item as it should.  
But when I first press Caps-Lock, the same combination of keypresses corresponds **Alt-Left** (also keycode 44 per `xev`, keysym 0xff51 "Left"), and the **Tabs menu drops down again** , despite me _not_ pressing Alt-t, and therefore preempts the intended behaviour of `backward-sexp`.

The (purely Racket) event-listener [1] is able to distinguish between the two cases, reporting Alt-t and Alt-Left respectively.

Does anyone know from the top of the head whether this menu issue is a hopeless Gtk issue, or if there's hope it could be fixed within racket/gui? (@robby @mflatt I assume)

**Edit:** `gedit` does not preempt Alt-Down (same keys as Alt-s, bound to Save), so I suspect this is a racket/gui issue.

**Edit2:** I don't understand where `label` is used to set the gtk accelerator: [gui/menu.rkt at master · racket/gui · GitHub](https://github.com/racket/gui/blob/master/gui-lib/mred/private/wx/gtk/menu.rkt#L90) I can't see a single use of it 🤔

* * *

[1] The event listener:

```scheme
raco pkg install racket-paint
racket -l racket-paint/event-listener

```
