Detecting non-ascii key presses?

I have some posts that can detect ascii key presses but I can’t find any resource on how to detect if keys like LEFT or RIGHT are pressed.

Basically, i want to wait for input of LEFT or Right and then do something then wait for another key.

But method I found literally move the cursor in the terminal.

Is there a simple method to wait for keyboard input and then detect what key is pressed even for non-ascii key-presses?

1 Like

I would use one of the terminal packages for Julia to respond to keypress events, rather than working with the low-level stuff directly. e.g.

2 Likes

I see here:

Terminals transmit characters, not keys.

[So also would be a problem for English vs. e.g. my Icelandic keyboard, unless that’s what you wanted out, not keypresses.]

That’s what I thought, you couldn’t even know let say (left or right) SHIFT key got pressed on Linux/Unix.

I tested with:

$ sudo less -f /dev/input/by-id/usb-DELL_Dell_USB_Entry_Keyboard-event-kbd

and at least the terminal does know that left or right shift was pressed (and I suppose you could decode which), but I need superuser access, so it’s a non-starter, and the file is slightly different than in the answer here:

So I still think it’s just not possible in Linux terminal (or rather, you need to make a graphical app). I would like to be proven wrong, or at least what you can detect, in a) Linux, Windows (and macOS).

Is there a (non-Julia) library that supports the all the three operating systems, that could be wrapped, or would that basically be Gtk or Qt?

The OP was asking about arrow keys, not shift or key-up events, and arrow key presses are sent just fine by terminals.

Yes, I realize that. I misread at first (“arrow” was only implicit), before posting my answer, but was curious enough to look into, e.g. for games, and posted anyway as might be of interest to some. Can you confirm my suspicion, that full support would be impossible in the terminal?

Sorry for confusing the issue, back to arrows only:

It seems at least arrow down might be problematic, scrolling the screen. I’m not sure. In most cases you could detect the key pressed, and undo that effect by printing back the opposite arrow?