vVv - Keypresses (again)

This is a discussion on vVv - Keypresses (again) within the Linux Programming forums, part of the Platform Specific Boards category; Hi vVv Thanks for the function you posted earlier on keypresses. It does, however only work once in my program, ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    29

    vVv - Keypresses (again)

    Hi vVv

    Thanks for the function you posted earlier on keypresses. It does, however only work once in my program, the rest of the function calls are just ignored. D'you know how to fix that ('cause I'm lost).

    Thanks in advance

    Skarr
    I like traffic lights. I like traffic lights. I like traffic lights, but only when they're green.

  2. #2
    vVv
    Guest
    Hey,
    can you post how you are using it in your code? Note that some special characters, such as the arrow keys, fx, etc are being received with scancode mumbo jumbo.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    29
    I just tested it in a program like:

    #include <stdio.h>

    char inchar(void);

    // The function here

    int main(void) {

    printf("%c\n", inchar());

    printf("%c\n", inchar());

    return 0;

    }

    And it only works the first time, the second is just skipped.

  4. #4
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    since you did not post the code for inchar(), i can only assume you expect a personal answer from vVv, which makes this thread useless to everyone else.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    29
    #include <termios.h>

    char inchar()
    {
    char c;
    static struct termios o, n;
    tcgetattr( STDIN_FILENO, &o );
    cfmakeraw( &n );
    tcsetattr( STDIN_FILENO, TCSANOW, &n );
    c = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &o );
    ungetc( c, stdin );
    return c;
    }

    Here ya go.

    Oh, and btw vVv, I'm not trying to scan for arrow keys, just normal letters.
    I like traffic lights. I like traffic lights. I like traffic lights, but only when they're green.

  6. #6
    vVv
    Guest
    Either remove the ungetc(), or read the data from stdin after calling ``inchar()''.
    Code:
    printf( "%c\n", inchar() );
    getchar();
    printf( "%c\n", inchar() );

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    29
    Yeah, but that takes out the meaning of the whole function, doesn't it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting multiple keypresses in a DOS compiler
    By Nongan in forum Game Programming
    Replies: 2
    Last Post: 04-01-2005, 09:07 PM
  2. thx vVv
    By wazilian in forum Linux Programming
    Replies: 1
    Last Post: 04-03-2003, 02:49 PM
  3. How to scan for keypresses?
    By Unregistered in forum Linux Programming
    Replies: 4
    Last Post: 07-09-2002, 01:18 PM
  4. Keyboard INT 9 handler (Handles multiple keypresses!) Problem
    By zhopon in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-16-2001, 09:39 AM
  5. Replies: 0
    Last Post: 12-16-2001, 09:36 AM

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