4

So, i have a problem; i'm trying to figure out how to either use the standard library or inline assembly to get raw keyboard or mouse input in a C/C++ program. I'm using Xubuntu 15 and GCC/code::blocks to build my programs.

I'm familiar with using inline assembly, so if it's possible to, say, move a specific register or memory address into a variable that just contained the current mouse position or last keyboard key pressed (This has to include the special keys like function keys or arrow keys.) That would be great for my C++ project.

Preferably, this would be compatible with any OS/x86-based architecture.

Mason Watmough
  • 495
  • 6
  • 19
  • 2
    You know it would help out answerers if you also mention why you're trying to do what you're trying to do. Sometimes there might be a better way to go about it than what you describe in your question.. – jrharshath Aug 28 '15 at 13:44
  • 1
    My ultimate goal is to create a small, fast and lightweight 2d game handler a bit like SDL or SFML but smaller. – Mason Watmough Aug 28 '15 at 13:47
  • 1
    The last line of your question certainly will not be possible. You could have pulled something like this off with a Real-Mode OS like DOS, since the BIOS handled these input devices and you had direct access to the memory that held the circular keyboard buffer and you could just fire an int or set an interrupt vector to handle the mouse input, but with a modern Protected Mode OS, this is never going to happen. You'll _need_ to ask the OS for these values. – enhzflep Aug 28 '15 at 14:19

1 Answers1

3

In Linux world, you can use

  1. https://stackoverflow.com/a/13129698/4776786 this will work in terminal. You press any key and you have his code, without pressing ENTER.

    http://asm.sourceforge.net/articles/rawkb.html - assembly version

  2. http://wiki.libsdl.org/SDL_GetKeyFromScancode Use SDL. Or type in terminal

    $: sudo apt-get source libsdl-image1.2-dev libsdl-mixer1.2-dev

to get source code of SDL library, and read for yourself how they handle keyboard keys.

Community
  • 1
  • 1
nanomader
  • 410
  • 9
  • 22