473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Reading keyboard input from a telnet session.

2
Hello all,

I am new to c++, coming from a Java background. Thank you in advance for anyone that can answer the question below:

GOAL:

I am currently writing a shell application for a telnet session. I wish to add functionality of a command buffer/history of past commands the user has
entered successfully. This action is similiar to pressing the up/down arrow on a standard prompt window and cycling through past executed commands.

PROBLEM:

I am having trouble listening to keystrokes. At first I tried to run select() on stdin with no timeout; however, select() blocks until the user presses the newline character on the prompt (press enter key).

Does anyone know of a way in the standard c++ library that you can read characters immediately after the user presses the key?

I wonder if the problem is that the telnet session is controlling the stdin and my program does not know of any input until the user presses the enter key, is this the case?
Sep 12 '07 #1
3 3296
weaknessforcats
9,208 Expert Mod 8TB
Your C++ Standard Library features require that you press the enter key before the program takes control. The user can enter any keys into the inout buffer but your program won't take charge until enter is pressed.

Your solution is to not use the C++ Standard Library.

With Windows you can process a WM_KEYDOWN event immediately.
Sep 12 '07 #2
Moogoo
2
Ok so the select() is a blocking function, unless you specify a timeout value?

So if I wanted to listen to keystrokes I would have to create my own thread to just read characters off the input stream?

e.g.
Expand|Select|Wrap|Line Numbers
  1. int i; char ch;
  2. while(true){
  3.  
  4.     i = read(fileno(stdin),&ch,1);
  5.  
  6.     if(i == 0)
  7.        continue;
  8.     else{
  9.        if(ch == "UpArrow") // don't know hexcode yet...
  10.            // process my command
  11.        else
  12.           // pass to shell
  13.     }
  14. }
Sep 12 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
You can't use read to listen for keystrokes. The buffer is not available until enter is pressed.

You have to call functions that can listen to keystrokes. In a Windows program you process the WM_KEYDOWN message. These messages are wired to the keyboard itself and do noit use stdin and do not read a buffer.

I don't know what the Unix equivalent is.
Sep 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Yannick Turgeon | last post by:
Hello all, I'm currently trying to pass commands to a telnet session and get the texte generated (stdin + stdout) by the session. The problem I get is that the Telnet.read_until() function...
4
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib,...
2
by: john brown | last post by:
I'm telnetting into a router. Apart from the fact I can't seem to view the output when iniciating the session, I can't match one of the expressions using Net::Telnet. I can telnet into the router...
5
by: richardtinkler | last post by:
I need to communicate with a POP3 server using ASP. Does anybody have any ideas how I can set up a telnet connection using an ASP script? There are some components out there, but my host won't...
2
by: Hoegje | last post by:
I am writing a C++ program, which should create a sub- process to start a telnet session to another server. Then it should login to that server (on the telnet login) and execute one or more...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
0
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as...
2
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as...
2
by: vmalhotra | last post by:
Hi I am new in python scripting. I want to open a Multiple telnet session through once script. In other way i can tell i want to open two linux consoles through one script. I wrote one...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.