[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using kbhit() and arrow keys in infinite loop

From: E. Joshua Rigler
Subject: using kbhit() and arrow keys in infinite loop
Date: Mon, 9 Mar 2009 15:30:41 -0700

Is there any way to read in the up/down/left/right arrow keys (or
other special keys) in an infinite loop?

Specifically, I want to interactively re-position one image with
respect to another in a manual search for pixel alignment (defined as
the closest thing to zero difference between the two).  I can use
regular ascii characters like "h,j,k,l" (think old-school vi), but it
would be much nicer if I could use arrow keys.  The problem is that
the arrow keys generate an escape sequence.  I know how to use C-q or
C-v to get the escape sequence, but kbhit() doesn't seem to return
enough information to make a proper comparison.  Here's some sample
code showing what I've tried:

while (1)
   udlr = kbhit();
   switch udlr
      case {"^[[A"}
        # shift image up
      case {"^[[B"}
        # shift image down
      case {"^[[D"}
        # shift image left
      case {"^[[C"}
        # shift image right
        # quit

The "^[" is the escape character, and is what seems to get read in by
kbhit().  The weird thing is that if I print out the udlr variable, I
get "A", "B", "D", and "C", but I think these are just the stdout
stream getting flushed.  Thanks.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]