-2

Short: help emulate keyboard events (arrow keys, enter) in C code under linux.

Long: I am working at interfacing iPod clickwheel with Raspberry Pi. At the moment i can printf to terminal something like "button 1 pressed". But i need system-wide event, just like a keypress from real keyboard. My other code is on C so i cant implement Python.

genpfault
  • 51,148
  • 11
  • 85
  • 139

2 Answers2

0

You can maybe use SDL2, it works with Raspberry Pi and Linux and you can manage inputs events such as keyboard, mouse, pads etc.

More info here: https://wiki.libsdl.org/SDL_Event

Valentin
  • 39
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 11 '21 at 19:08
  • Thanks but i cant find simple enough example of this pretty new to me library. I would be happy to find something like this proto code: keyboardEvent(KEY_UP,1); – production Oct 16 '21 at 13:19
  • Simple example of how you could write a piece of code that manage the key input: ` SDL_Event event; bool continuer = true while (continuer) { SDL_WaitEvent(&event); switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_1: continuer=false; `break;` `}` Code loops forever until the 1 key is pressed. Find more info if you search for "How to manage SDL events and inputs – Valentin Oct 16 '21 at 14:02
0

You really should use third-party libraries. There's definitely no platform-independent way to do it in ANSI C. You can try using conio.h with its kbhit() function , the library can be downloaded from conio.

Or you can read the up /down /right /left keys from the terminal like

Akki
  • 96
  • 1
  • 7