[Novalug] keyboard/console input blocking problem

greg pryzby greg@pryzby.org
Thu Oct 11 18:33:39 EDT 2012


That helps, it is a command line app that is waiting for EOL. cin in
c++. The X app doesn't matter, so why mention it :D (kidding!)

I am going to argue that cin is the wrong object (?) to use. I am not
sure what method you are using

 #include <string>
  inline int PressAnyKey( const std::string& prompt = "Press a key to
continue..." )
    {
    return PressAnyKey( prompt.c_str() );
    }

While get each key. You will need to concatenate and do some work to
build words, strings, lines etc. But you want a single character vs
line.
   cin.get() might work


Here is a discussion about what you MIGHT be doing. i am not sure why
you are reading a character at a time and what you want to do
   http://www.velocityreviews.com/forums/t290196-how-to-read-a-single-keystroke-in-c.html

getch() in C


On Thu, Oct 11, 2012 at 6:04 PM, Ed James <edward.james@gmail.com> wrote:
> Hi Greg,
>
>    I'm way past the tutorial stage, which is why I'm hitting the more
> complicated issues.  I know how to deal with keyboard input that
> is entered when the X Window created by myProgram has focus.
> Thar's just pulling stuff off the event queue.  I've written quite a few
> X Window programs, including my own widget library from scratch
> using C++.
>
> My problem deals with reading keyboard data from the terminal emulator
> (which launched myProgram) when it has input focus.
>
>    The terminal window is just a simple command-line interface.  When
> the myProgram window has focus, it's a blank window that doesn't do
> anything, but does capture mouse and keyboard activity and results in
> event queue activity.  That's the easy part.  But move focus to the terminal
> window, and stuff typed into the terminal window is read by myProgram
> when I hit <ENTER>.  That's just a simple read via the C++ cin.  The
> problem is that the terminal reading is blocked until <ENTER> is hit,
> so my input loops blocks.  I'm trying to un-block it, similar to using
> a socket in nonblock mode.
>
>    So, the answer to your question is I'm using cin in a C++ program to
> read console/keyboard input.
>
>    I don't know much about recordmydesktop, except for about 2 minutes
> of googling when you suggested it.  It seems interesting, so I'll check it
> out, and tnx for that suggestion.
>
>    One more thing - if worse comes to worse, I'll just abandon trying to
> capture terminal input commands and collect the keyboard input via
> the event queue.  It's a kludge, but if it work...yay!  Meantime, I'm
> playing with pthread code.
>
> Ed James
>
> On Thu, Oct 11, 2012 at 5:40 PM, greg pryzby <greg@pryzby.org> wrote:
>> recordmydesktop can help show what you are trying to do.
>>
>> what command are you using to read keyboard input?
>>
>> http://user.xmission.com/~georgeps/documentation/tutorials/Xlib_Beginner.html
>> This might help but w/o knowing HOW you are doing it now, I can't be
>> sure. I think the example will capture EACH keystroke, which is what
>> you want.
> ...
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/novalug



-- 
greg pryzby                              greg at pryzby dot org
http://www.linkedin.com/in/gpryzby

WEB:  http://www.MakeRoomForArt.com/
TWTR: gpryzby



More information about the Novalug mailing list