How can we read two character from keyboard at same time in c language - c

I am working on project in which my requirement is to use two arrow keys( like UP,DOWN,RIGHT,LEFT)
at same time. How can I read from user if any of two arrow keys are pressed at same time
I can read arrow key using getchar() but only applicable to single key.
Any Advice
Thanks in advance

Related

use both keyCallback and GetKey

I'm currently trying to learn openGL and I am using GLFW.
in the window, I am using the glfwSetKeyCallback function for single key presses/ key combinations (like CTRL + q or ESC for closing window with a switch statement) and I am using another function that runs every few milisecond for constant keypresses (like W for moving forward or A for moving left using multiple if statements)
seperating the two usecases in two different function makes it easier for me, but I was wondering if it was a good idea to use them like that or if I should use all the different usecases in a single function, either the callback or the one that is called every few miliseconds. (I hope that was clear)
Thanks in advance for your advice !

Get input without pressing the ENTER key - In C

As you can understand from the title, I want to get input from the user without pressing the ENTER key.
If I need to talk about the program I want to do:
I'm writing a keyboard speed test program. And as you can guess I want to get the input with the SPACE key, not the ENTER key.
The program I designed was like this:
Example text = "... an apple ..."
I will take every key the user presses and check if that key is an SPACE key .If this key is the SPACE key, I'll change to the new word.
I've reviewed other similar topics on this site. If what I wanted to tell was complicated or I couldn't explain it, let me say it. In games, it is enough to press the SPACE key to jump. There is no need to press the ENTER key.
I want something like this. And I want to do this using the standard library of c if possible. I don't want to use any 3rd party libraries.
One more addition: The function I want is a function similar to the getchar() function. The only difference; I want to get input without pressing the ENTER key.

How can I recognize keys from a second keyboard?

I bought a second keyboard, USB with 20 programmable keys. I'm using Windows.
The programming utility foresees using it for gaming, for macros, or as a number keypad, but I need it for another script - I don't want to duplicate keys I already have on my normal keyboard.
I notice that normal keycodes for the function keys F1-F12 are 112-123, but this utility offers me function keys F1-F20, presumably with codes 112-131. For my 20 extra keys, I'd like to use 124-143, as if they were F13-F32: I want to be able to recognize keys from the second keypad unambiguously. NumLock is 144, but there doesn't seem to be any codes in my range.
But is there a correct or better way to do this? I can't be the first person to want to add more keys to a keyboard.

Codename One - Key binding for "p" is not working?

I am trying to attach Commands to buttons. This method works for 'q' and 'm', but it is not working for 'p' character.
Using '-112' did not solve the problem either. using minus symbol works for arrow keys but not for 'p'.
addKeyListener(113, new CommandA(gameWorld)); // q
addKeyListener(109, new CommandB(gameWorld)); // m
addKeyListener(112, new CommandC(gameWorld)); // p - Not Working
pressing 'p' does nothing.
UPDATE
Found a workaround...
This won't work for you on the device anyway as most devices are touch devices. The virtual keyboards on such devices don't send these events anyway. The arrow keys send undocumented values which differ a lot and you should "theoretically" use the game key API and not the key API. But again this won't work on the devices most commonly used today.
The characters aren't just numbers. They are literally the character value (int)'p'. There is no special treatment for them but it's possible that something in the system is grabbing that specific character as it's commonly associated with a print shortcut.

ASCII character from VK_Code

I have a small WIN32 C-Application in which i work with the KBDLLHOOKSTRUCT structure. This structure contains the VK-Code for a pressed key.
I try to convert this to an ASCII-Character. For this i use the Function MapVirtualKey, which works well.
The only problem is, that one VK-Code can stay for multiple chars.
Example:
On my keyboard (Swiss-German) exists the key-char .. If i press Shift+. then it creates a :. The VK-Code is the same. Thats no problem, and i can also check if Shift is pressed or Caps Lock is activated.
My only problem is: How can i get the char ':'?
I need a function like this:
GetKeyChar(vkCode, shift)
I need this to get the "normal" and the "shifted" value of the keyboard. Of course i could hardcode this, but i don't like to do it on this way.
The problem is that the KBDLLHOOKSTRUCT doesn't have all the information you need in order to do the translation. You get a message every time a key is pressed. So for Shift+X, you'll get an input message saying that the Shift key was pressed, and another message saying that the "X" key was pressed.
You need to call GetKeyboardState in order to get the state of the Shift, Alt, Ctrl, (and perhaps other) keys. Then call ToAsciiEx or ToUnicodeEx.
You're looking for ToUnicode, which returns the unicode character generated by that keypress.
The functions you are looking for are: ToAscii, ToAsciiEx, ToUnicode, ToUnicodeEx.
short VkKeyScan(char ch) API has contained the shift information. It translate char to virtual-key code and shift state.
See this: Convert character to the corresponding virtual-key code

Resources