howto grab key strokes directly?

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default Re: howto grab key strokes directly?

    ups, ok hier nochmal auf deutsch:



    Wie veranlasse ich mein C Programm dazu direkt auf Tastendruecke zu
    reagieren?

    Standardmaessig wird das doch (soweit ich weiss) in einem
    Line-Puffer zwischengepseichert. Erst mit <return> bemerkt
    select() etwas am Eingang. Ich moechte aber beispielsweise direkt
    in einer Endlos-Schleife mitbekommen, wenn Ctrl-q gedrueckt wurde.

    Wie mache ich das?

    Nach welchen Schlagworten muss man da eigentlich suchen?
    Kann man einfach so den Standard Modus von stdin aendern und kurz vor
    Programmende wieder herstellen oder gibt es da Komplokationen?

    Vielen Dank schonmal,
    Christoph


    C.Hagedorn Guest

  2. Similar Questions and Discussions

    1. Grab ID or DIV sections From ASP
      Hi, Is it possible to grab some sections or tags using ID on a HTML page ? I m working on a adserver project that allows to track users on...
    2. Grab HTML
      I'm looking for a way to grab the HTML behind one of my pages and display it to the user. The page I'm trying to get the HTML from is an ASP page,...
    3. Content grab / extraction
      Dear all, Hopefully there´s someone who can help me. I´m looking for an ASP/Javascript possibility to grab content from another website and...
    4. is there a way to grab more memory for Director to use?
      Hi! Post some of your animation code, and we wil have a look at it. Sounds strange that it's slow, so it must be something with the code. ...
    5. How to grab HTML source?
      "Mike Darrett" <mike-nospam@darrettenterprises.com> schrieb im Newsbeitrag news:d945119c.0305021419.3f461b9f@posting.google.com... hey mike -...
  3. #2

    Default Re: howto grab key strokes directly?

    there must be several ways of doing this, here is one:

    - in your program include <termio.h>
    - have a statmement: struct termio save, term;
    - use ioctl to read terminal settings into term structure
    - save a copy of term into save structure
    - term.c_lflag&= ~ICANON;
    - term.c_cc[VMIN] = 1;
    - term.c_cc[VTIME] = 0;
    - set nbew state with new call to ioctl(0, TCSETA, &term);
    - your loop follows here, reading one char from stdin each time:
    read(0, &in, 1);
    where in is a char variable.
    - process every input
    - when loop is broken then reset old state with:
    ioctl(0, TCSETA, &save);

    It may help.

    raymundo

    C.Hagedorn wrote:
    > Hi all,
    >
    > i want to write a console application with an infinite loop, which
    > reacts on key strokes like Ctrl-q for example to end the loop .
    >
    > How can i do this?
    >
    > I figured out to use select() to get noticed if stdin has data to read,
    > but i still have to press Enter to confirm the input.
    >
    > How can i set stdin again within my application to get
    > unbuffered, non-blocking (no suspend of the process) input?
    >
    > The select() function is a good step, but how to switch off <cr>?
    >
    > Thanks in advance,
    > Christoph
    >
    >
    Raymundo M. Vega Guest

  4. #3

    Default Re: howto grab key strokes directly?

    [email]mdanko@tesla.rcub.bg.ac.yu[/email] (Darko M.) wrote:
    >Wow! This is really something. Is it yours or did you pick it up in
    >some header? I the answer is "It's mine" then please tell me where's
    >all the terminals' stuff documentation, because it definitely isn't in
    >Stevens (not that much).
    >
    >It would be a really precious information, thank you.
    I've been posting that to Usenet for well over a decade. It has
    evolved significantly because it originally used termio and
    pre-dated ANSI C, but since about 1993 has used termios.
    Actually, that particular version has modifications that were
    not in it the last time I posted it. I changed all uses of file
    descriptor 0 to use STDIN_FILENO instead, and reformatted it
    eliminate lines longer than 64 characters. There are a couple
    of other changes that I'm thinking of, which might be made the
    next time it is posted.

    I believe, but have not verified, that virtually everything
    needed to understand what it does is in fact in Stevens, though
    it might be spread around in too many different places to be
    obvious. That is why I've bundled it with an example "menu
    program" as a demo.

    Other sources of information are also spread out. The man pages
    for stty, termios, and each function used in the program should
    all be read. The C FAQ and the FAQ for this newsgroup are also
    required reading.

    --
    Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
    Ukpeagvik (Barrow, Alaska) [email]floyd@barrow.com[/email]
    Floyd Davidson Guest

  5. #4

    Default Re: howto grab key strokes directly?

    C.Hagedorn wrote:
    > Hi all,
    >
    > i want to write a console application with an infinite loop, which
    > reacts on key strokes like Ctrl-q for example to end the loop .
    >
    > How can i do this?
    >
    > I figured out to use select() to get noticed if stdin has data to read,
    > but i still have to press Enter to confirm the input.
    >
    > How can i set stdin again within my application to get
    > unbuffered, non-blocking (no suspend of the process) input?
    >
    > The select() function is a good step, but how to switch off <cr>?
    Christoph

    Take a quick look at [url]http://www.iedu.com/mrd/c/getch.c[/url] for a
    program written with info from Stevens' "Advanced Programming in
    the UNIX Environment".

    HTH
    --
    Morris Dovey
    West Des Moines, Iowa USA
    C links at [url]http://www.iedu.com/c[/url]

    Morris Dovey Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139