Results 1 to 5 of 5

Thread: C code - get key press - no echo - a to z and 0 to 9

  1. #1

    Default C code - get key press - no echo - a to z and 0 to 9

    I need to wait for a key, 'n', then continue. No echo of character. You don't have to press enter.

    Code:
    #read -n 1 -s -r
    This works in bash. If I try using the 'system' function, I get a keyboard freeze, but no key will continue.

    https://linux.die.net/man/3/system

    system("read -n 1 -s -r");

    How to make this work? Else, some other way to wait for a keypress in C.

    Help....

  2. #2
    Join Date
    Jan 2014
    Location
    Idaho
    Posts
    89

    Default Re: C code - get key press - no echo - a to z and 0 to 9

    Have you tried using the console I/O function? i.e. getch()

  3. #3

    Default Re: C code - get key press - no echo - a to z and 0 to 9

    Quote Originally Posted by J_Andrew View Post
    Have you tried using the console I/O function? i.e. getch()
    If you mean ncurses-devel, yes. It gives this error.

    Code:
    #include <curses.h>
    //int getch(void);
    
    getch();
    Code:
    /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /tmp/ccMMPcLf.o: in function `Scan_Results_Filter':
    scanvirus.c:(.text+0x538): undefined reference to `_nc_stdscr'
    /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: scanvirus.c:(.text+0x540): undefined reference to `wgetch'
    collect2: error: ld returned 1 exit status

  4. #4

    Default Re: C code - get key press - no echo - a to z and 0 to 9

    I need to have the screen unaltered to trace the program logic.

  5. #5

    Default Re: C code - get key press - no echo - a to z and 0 to 9

    I got it working by adding "gcc -g scanvirus.c -o scanvirusbin -lncurses"

    It doesn't work. I can't get getkey to work. Any method using ncurses, clears the screen. This will not work either for my code.

    Still need help....

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •