Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirecting key's maybe...
#1
Something I mentioned in the book and said I would come back to, but it seems the come back, got cut in the edit....which is not surprising because this "fix" is only partially effective.

Basically we need to stop the normal linux key responses from happening when we  are pressing keys for our game... we don't want to see a lot of WWWSSSSSEEEEEE   EEE  in our terminal when we quit the game, or worse a mouse actually opening a desktop app or folder under our game image. Linux is always working in the background so we have to stop it acting on key and mouse inputs.

So the traditional way is to redirect our key systems to a null file....like this, it overrides the key and stops them being echo'd so no input will happen...nice.
You'll need these headers
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdio.h>
// this lets us redirect our OS keyboard systems
    
// we need to save the original terminal io settings
struct termio original_termio;
struct termio new_termio;

    int fd = fileno(stdin);
    ioctl(fd, TCGETA, &original_termio);

    new_termio = original_termio;
    new_termio.c_cc[VMIN] = 0;http://gleenders.blogspot.nl/2014/08/banana-pi-resizing-sd-card-root.html
    new_termio.c_cc[VTIME] = 0;
    new_termio.c_lflag = 0; // stop echo (and other things)
    
    ioctl(fd, TCSETA, &new_termio);

// and this puts them back when done
    fd = fileno(stdin);
    ioctl(fd, TCSETA, &original_termio);  // put the old one back

Now that's perfectly ok unless you are using VisualGDB...because visual GDB applies another redirect to get data back from the target....so it overrides our override.
That is a bit of a pain, but while it will impact on us when running our debug systems, we can be confident that running the projects directly from console/gui will be fine (since VisualGDB isn't in place to override the override)

Conversely if you are using Visual Studio for Linux... it will stop GDB sending data to your debugger.....we suffer in different ways. 
Keep your terminals closed, don't have too much clickable stuff on your desktop and just live with it, the ability to debug is worth a little bit of key echo, but any distributed final builds need to have this
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)