What is the C API for reading the keyboard scancodes in userspace ?

This is a discussion on What is the C API for reading the keyboard scancodes in userspace ? within the C Programming forums, part of the General Programming Boards category; That is the question, Kindly guide !...

  1. #1
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115

    What is the C API for reading the keyboard scancodes in userspace ?

    That is the question,

    Kindly guide !

  2. #2
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    Oh perhaps termios struct can be used here !

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    The FAQ has an example of simulating conio.h's getch function using termios.
    My best code is written with the delete key.

  4. #4
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    Thanks for replying!
    I forgot to mention in my OP that i am using Linux, conio.h doesn't work there !

    Still I discovered a piece of code:
    Code:
    int mygetch ()
          {
          struct termios oldt,      newt;
          int ch;
    
          tcgetattr( STDIN_FILENO, &oldt );
    
          newt = oldt;
    
          newt.c_lflag &= ~( ICANON | ECHO );
    
          tcsetattr( STDIN_FILENO, TCSANOW, &newt );
    
          ch = getchar();
    
          tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
          return ch;
    }
    This code works fine with all keys except Ctrl, Alt !
    It simpy doesn't read them . Can some one point out why ?

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I forgot to mention in my OP that i am using Linux
    I assumed you were using Linux since you mentioned termios. Oh well, you can lead a newbie to the FAQ, but you can't make him read.

    >conio.h doesn't work there !
    I know that. Read all the way to the bottom of the FAQ and you'll find a Linux friendly example using termios. The piece of code you "discovered" looks to be a knockoff of our FAQ's version with slightly different formatting. The end result is the same, but you probably wasted more effort than was necessary by failing to read the FAQ in its entirety.

    >It simpy doesn't read them . Can some one point out why ?
    Perhaps because they don't do anything meaningful except in conjunction with another key? How much do you know about scancodes?
    My best code is written with the delete key.

  6. #6
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    Thanks for the nice link,

    I didn't read the FAQ till end because i failed to read the word simulating in your following post.
    The FAQ has an example of simulating conio.h's getch function using termios.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 03:46 PM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 07:51 PM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 04:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21