473,804 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ using keyboard system inputs

RADAR
21 New Member
i use VC++ 6,0 and i have problems with getting keyboard system inputs and to use them to check to proceed or break the loop.
for example if i want to proceed until Ctrl+z is written for input.What will the compiler do?Does it accept Ctrl+Z as a normal string input , char* input, or a char input which has ASCII 26...
suppose i have a loop that does the following:
-first check the choice
-if not Ctlr+Z continue
-else go to the next stage.


"%
i only need when Ctrl+Z is performed using keyboard and it is gotten by select,it should exit the loop..
%"

i tried to do sth:
Expand|Select|Wrap|Line Numbers
  1. char select;
  2. string str;
  3.  
  4. while(select != char(26)) //--char(26) is the ASCII equivalent of Ctrl+Z , i guess
  5. {
  6.              cout     <<" Enter a string";
  7.             cin >>str;
  8.             locate_asterisk(str);//--a function that adds '*' after each char in a cpp          
  9.                                         //--string
  10.             cout       <<"If you want to continue, press any character"
  11.                          <<"or to exit perform Ctrl+Z from keyboard"<<endl;
  12. }
  13.  
by pressing Ctrl+Z some strange characters appear; like ^Z
i was trying this for more than 10 hours but i was really confused on what to do.
I will be very pleased if any helpful ideas are provided by you;
thanks for now
RADAR
Dec 27 '07 #1
7 3419
gpraghuram
1,275 Recognized Expert Top Contributor
i use VC++ 6,0 and i have problems with getting keyboard system inputs and to use them to check to proceed or break the loop.
for example if i want to proceed until Ctrl+z is written for input.What will the compiler do?Does it accept Ctrl+Z as a normal string input , char* input, or a char input which has ASCII 26...
suppose i have a loop that does the following:
-first check the choice
-if not Ctlr+Z continue
-else go to the next stage.


"%
i only need when Ctrl+Z is performed using keyboard and it is gotten by select,it should exit the loop..
%"

i tried to do sth:
Expand|Select|Wrap|Line Numbers
  1. char select;
  2. string str;
  3.  
  4. while(select != char(26)) //--char(26) is the ASCII equivalent of Ctrl+Z , i guess
  5. {
  6.              cout     <<" Enter a string";
  7.             cin >>str;
  8.             locate_asterisk(str);//--a function that adds '*' after each char in a cpp          
  9.                                         //--string
  10.             cout       <<"If you want to continue, press any character"
  11.                          <<"or to exit perform Ctrl+Z from keyboard"<<endl;
  12. }
  13.  
by pressing Ctrl+Z some strange characters appear; like ^Z
i was trying this for more than 10 hours but i was really confused on what to do.
I will be very pleased if any helpful ideas are provided by you;
thanks for now
RADAR
Usually Ctrl+Z generates the SIGHUP signal in Unix and i am sure that you can handle it only with catching the signal.
But i am not sure whether yopu will be able to read it using cin/scanf


Raghuram
Dec 27 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
The crl+Z is the end-of-all-input signal. You must press <enter> to put that in the input buffer. Without it, an inout loop will run forever askign for more input.

Everything you type is echoed to the screen.
Dec 27 '07 #3
RADAR
21 New Member
thanks for trying but i still couldn't do it.
i only want if ctrl+z is entered , the while loop will end the program will continue until the return 0; statement as usual.
thanks again guys.
respects,
radar
Dec 28 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Your code sampoe does not work since select is never initialized and you never use it to get data from the keyboard. Try this:
Expand|Select|Wrap|Line Numbers
  1. string str;
  2. cout     <<" Enter a string";
  3.  
  4. while(cin>>str)
  5. {
  6.              locate_asterisk(str);//--a function that adds '*' after each char in a cpp          
  7.                                         //--string
  8.             cout       <<"If you want to continue, enter a string"
  9.                          <<"or to exit perform Ctrl+Z from keyboard"<<endl;
  10. }
  11.  
Dec 29 '07 #5
RADAR
21 New Member
thank you very much for your help , this is so clean and strong answer for my question.i wonder if you can only answer one more question , why do i have to initialize the string variable?
Dec 29 '07 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
why do i have to initialize the string variable?
Every variable needs to be initialized otherwise it just contains the random bits in memory where it was allocated. One of the biggest error areas is in using uninitialized variables. C++ constructors are a way to automate this process.
Dec 30 '07 #7
RADAR
21 New Member
thank you so much.
that helped me a lot...
Dec 30 '07 #8

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

Similar topics

0
2669
by: Hiroyuki Tanaka | last post by:
Hi All, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to my Completion ComboBox using sendkey.wait. From the keyboard (that will not exist for my final application) I can enter text into my Completion and the selection completes as expected.
6
3166
by: Brian Basquille | last post by:
Hello all. Due to the short time remaining to my project handup for my Air Hockey game, i've abandoned the idea of implementing it over a network. But since the only real way to play Air Hockey is using a mouse, i was wondering if it is possible for 2 people to use 2 mouses while on the same computer? For example, 1 mouse could be in USB port and other in PS/2 port. Does C Sharp support this? And if so, can anyone point me to some...
0
1451
by: Srin | last post by:
Hi, I'm in the process of writing a small C# App, in which i have two groupboxes in a form. The form has the KeyPreview property set to true. The groupbox1 contains a set of labels. The second groupbox contains a few checkboxes and a button. I wrote a form1_keypress handler to handle keyboard inputs directed at the form. But once the groupbox2 receives focus (if i change one of the checkboxes or click on the button), even before i can...
0
2750
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) To map "Keys" objects to their string constant, and stored them on a string Queue as they were happening. Then (after resetting the form), I simulate replaying of these actions by flushing the queued...
18
20471
by: Rose4msm | last post by:
hello can any one please help me i have a test and i need to study the java scripts, i know that i have to use arrays but im still a bit confuse the question is to ask the user how many data items he/she has using N, then i have to ask the user to input the N Data times (we assume that all the data are integers from -100 to 100 inclusive) then it has to output the maximum and the minimum value of the users data, please can any one help me or...
3
1982
by: Adrian Luck | last post by:
Hi, Is it possible to send mouse left click signals/inputs and keyboard inputs from a flash application to another program?
10
6585
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
3
7323
by: bwgames | last post by:
Hi there, I have a script that takes two inputs from the keyboard to change some settings on some equipment. I would usually run this as e.g. ben@srv001:/$ change-settings<enter> new-setting 1 <enter> new-setting2 <enter> Settings successfully changed ben@srv001:/$
2
9490
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
I am trying to find a good example of SendInput. Doing a search on google I found two, one is incomplete and vague from the start and the other I copied the code and tried running it and it was first of all incomplete (compiler errors) which I had to resolve by guessing on some things like how some variables were instantiated, and then finally it doesn't work. Ok, maybe I guessed wrong, but I shouldn't be guessing on what the code should...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.