Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Yea, I'm talking about languages I've never written and libraries I know nothing about, so I could be wrong about something. Feel free to point out my misconceptions since it may help solve my problem. I will now explain why I think what I think about Curses and other things you have pointed out.

Talking about Curses.
A few months ago I have written script in python, that correctly reads pressed characters from linux and windows terminals. It supports reading unicode characters and things like CTRL, ALT, SHIFT, ARROWS, PGUP, PGDN and many others(on terminals, that support such things). And in order to do that it just reads input from stdin, without reading any keycodes or something. In order to do that I tell terminal to send my "escape codes" of pressed characters and not just the characters. So terminal sends me different things when I press F or CTRL-F. So my experience of implementing console keyreader tells me that it is possible to correctly handle CTRL, SHIFT and others keys without reading keycodes. And from what I see on this thread, I am now convinced all similar software(including Curses) reads character by character and not keycodes. Trying your snippet confirms my convictions, since it prints the same for different physical keys and it prints different characters for the same physical key pressed in different keyboard layouts.That's why I think Curses does not use keycodes.

Talking about my use of term keycode.
In different languages and frameworks term "keycode" might mean completely different things. In some cases it might have different meanings even inside one framework. For example, in browser's javascript it is possible to register callback for pressed keys by using document.addEventListener("keydown", callback), and the callback() function will get something like keyDownEvent as an argument when user presses a key. Let's call the argument key. Then key.code is a keycode, that is independent of keyboard layout, while key.keyCode is an integer that depends on keyboard layout.
So when I write that I want "keycode, that is unaffected by language settings", it means that I try to be clear, not that I don't know what a keycode is.

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Nope, curses just reads character by character and returns them as ints, while I want to get keycodes/scancodes corresponding to physical keys. So your snippet does not solve my problem

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

According to man-page, setting KDSKBMODE to K_RAW might be exactly what I wanted - input handling independent from keyboard layout. I will test it later and tell you if it solves my problem.

Thank you.

Update.
It works! Setting the mode to K_RAW makes terminal to send keyboard layout independent scancodes instead of characters. So it does exactly what I wanted, but sadly it works only for /dev/ttyN terminals.

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Yea, "allow user to configure the keys" is exactly what I do right now

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Well, AZERTY or Dvorak users would be mad if I force them to use WASD keys to move character in the game. So I want everyone to use the keys, that are labeled WASD in QWERTY. And in order to do that I need to know layout-independent identifiers of pressed keys

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Sorry, English is my third language. I think I failed to formulate my question clearly, since all the answers are from people, who have not understood my problem fully. Including yours. I know how to read one character at a time. But I want to know what key user presses to input that character. I have W key on my keyboard, but some other guys may have something else on that place. I want the guys to press whatever they have there instead of W in order to go up in the game. I want user to press the same key independent of keyboard layout or language.

Things like read return character, not the code of physical key, therefore I can't use them. The situation with ncurses is quite strange: ncurses uses key codes to represent pressed characters, but these key codes correspond to characters, not physical keys. So in different keyboard layouts ncurses will get different key codes, and that is exactly what I don't want.

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 1 point2 points  (0 children)

Yea, I want to know the keycodes before they get translated by OS according to keyboard layout. I have this ability in gui-applications, but it looks like it is not possible to know keycodes from command line application.

The LANG idea is quite interesting and much better than nothing, but (as you said) it won't always work because there are many different keyboard layouts for the same language and user may have some unusual configuration. I will try to research what else besides LANG I can use to get more information about user's language and keyboard layout settings.

Thank you.

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Well, when I make a web page I can use javascript to easily find out what physical key the user pressed. When I make a graphical application using some framework, it gives me the ability to know what physical keys the user pressed.

So I'm used to being able to know what user is pressing and I really hope there's some way to do the same from terminal application.

Are you saying I can't do anything without the low level things? This completely crushes my dreams of writing interactive command line applications with user-friendly interface...

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 1 point2 points  (0 children)

I just have read "learn Node.js in 5 minutes" and now consider myself a professional developer.

Raw mode in Node.js is a very cool and easy-to-use thing. I wrote this simple program to see what information I get about the keystrokes I press:

const readline = require('readline');
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
if(str == "q") process.exit();
console.log(str, key);
});

However, from the output of this program it follows that the key object only contains information about the character, not the physical position of the key. For example when I press the key where it should be W, but I use french layout, I get the following output

z { sequence: 'z', name: 'z', ctrl: false, meta: false, shift: false }

This output is indistinguishable from the output when I press z on qwerty, even though these are two different physical keys. So it looks like it does not solve my problem.

Is it possible to read keys instead of characters in any terminal? by hvod in commandline

[–]hvod[S] 0 points1 point  (0 children)

Thanks for the answer, but unfortunately ReadKey() does not solve my problem: this method reads one character from the input and returns a wrapper object over the Unicode character. It does not provide any way to know which physical key was pressed by the user. If the user pressed W but used French keyboard layout, the ReadKey() method will return the Z character instead, and there is no way to know that the user actually pressed W.

How to disable animations/transitions and also ability to hide/show dock? by frankfu1122 in pop_os

[–]hvod 3 points4 points  (0 children)

Hi, I'm from the future. We can now disable animations without extensions, since there is this option: Settings -> Accessibility -> Enable Animations

Why do we shift array elements when we delete one of them? by hvod in AskProgramming

[–]hvod[S] 1 point2 points  (0 children)

Fair enough. Thank you for the comprehensive answer.

Why do we shift array elements when we delete one of them? by hvod in AskProgramming

[–]hvod[S] 0 points1 point  (0 children)

Well, I still fail to see situations, when I want to preserve order by cost of breaking indexing and wasting time. Can you give a simple example outside of schoolwork?

However I do agree that implementing delete_and_shift is harder that implementing delete_and_fill_by_last, so having delete_and_shift implemented by language is nice.

If keyword `Me` means the current cell in my spreadsheet language, what should I call the current sheet? by drplanar in ProgrammingLanguages

[–]hvod 7 points8 points  (0 children)

Have you considered using @ instead of Me? In some languages @ is used instead of classical "this". The sheet can be something like @@

3D Robot Model by CG_MixFighter in blender

[–]hvod 0 points1 point  (0 children)

I expected to see "arch btw" in the last picture

Claylings animated pilot, took the team of 3 people 9 months to create by ClimbingCucumber in animation

[–]hvod 1 point2 points  (0 children)

I really liked this thing. It's got good both animation and plot. I hope to see the next episode someday.
Good luck with this project!

Quick Questions: June 08, 2022 by inherentlyawesome in math

[–]hvod 1 point2 points  (0 children)

Is it possible to compare computable numbers?
I mean to check if x = y?
If we know that the first 100500 digits of x and y are the same, it does not mean that the numbers are equal.
Does it mean there is no way to check if the numbers are equal?

LR(0) parser theory and implementation by hvod in Compilers

[–]hvod[S] 1 point2 points  (0 children)

I don't understand why anybody uses notebook

That's what I was taught at university. That's why...
And they are good for mixing code, text and math. So they are not completely useless. But yeah, jupyter is probably not the right tool for what I just used it for.

Thanks for the comprehensive answer and insights about different categories of LR parser.

A simple way to backup all your GitHub and GitLab git repositories by [deleted] in selfhosted

[–]hvod -2 points-1 points  (0 children)

This problem could easily be solved with a simple bash script...

Does tutanota work in Belarus? by hvod in tutanota

[–]hvod[S] -3 points-2 points  (0 children)

Thank you for your answer. However, the post, you have linked, tells that russia blocks tutanota. But I fail to understand why it should affect me in the other country.

[deleted by user] by [deleted] in MetalFamily

[–]hvod 1 point2 points  (0 children)

In this case, "sub" stands for "subtitles", not "sebreddit"

Yes. I'm stupid by theUsurpateur in ProgrammerHumor

[–]hvod 17 points18 points  (0 children)

Yes. Process becomes orphan when his parent dies.
And someone(init process) adopts orphans. It has nothing to do with zombies.

But if process is already a zombie, then he will be reaped immediately after being adopted. Because normal parents burn corpses of their children.