Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,398 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,108 people online right now. Registration is fast and FREE... Join Now!




press keys

 
Reply to this topicStart new topic

press keys, c++

NyeNye
27 Oct, 2006 - 02:20 AM
Post #1

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
If how could i modify a hot keys for example i want to quit a program i just press q for

exiting the programs how could i do that???
User is offlineProfile CardPM
+Quote Post

ihatepikingnames
RE: Press Keys
27 Oct, 2006 - 07:29 AM
Post #2

D.I.C Head
Group Icon

Joined: 31 Jul, 2006
Posts: 115


Dream Kudos: 75
My Contributions
My bad... wrong window

This post has been edited by ihatepikingnames: 27 Oct, 2006 - 07:32 AM
User is offlineProfile CardPM
+Quote Post

Antiokus
RE: Press Keys
27 Oct, 2006 - 07:42 AM
Post #3

D.I.C Head
**

Joined: 6 Sep, 2006
Posts: 127



Thanked: 1 times
My Contributions
Youd have to use a scan or listen to the keyboard input and if 'q' then exit kind of thing. post your code and we can help a more with your problem.
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Press Keys
28 Oct, 2006 - 05:05 AM
Post #4

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
i just wanna get your idea...

to how it would be...
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Press Keys
28 Oct, 2006 - 08:00 AM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
CODE

if(myvar=='q')
   exit(1);

is probably the simplest example, but may not be what your looking for as the original information is not complete. Are you prompting for input? Scanning or polling?
User is offlineProfile CardPM
+Quote Post

CBart21
RE: Press Keys
28 Oct, 2006 - 08:03 AM
Post #6

New D.I.C Head
*

Joined: 28 Oct, 2006
Posts: 7


My Contributions
CODE

string exitVar;
getline(cin, exitVar);
if (exitVar == "q") exit(0);


Hope that works.
User is offlineProfile CardPM
+Quote Post

Antiokus
RE: Press Keys
28 Oct, 2006 - 12:02 PM
Post #7

D.I.C Head
**

Joined: 6 Sep, 2006
Posts: 127



Thanked: 1 times
My Contributions
Maybe im wrong, but doesnt Cbarts code require them to press enter? I was under the impression they want to listen for it instead of having the user press enter after it, in other word, not being prompted for it.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Press Keys
28 Oct, 2006 - 12:07 PM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
CBart's code does require an enter key, and will not work if the user is expecting to auto detect any key press. That's why I'd asked the user to be a little more clear on what they're looking for - simple user prompts, or a method to poll the keyboard (I suspect the latter).

That being said, much will also depend on what type of application it is, and what is used to implement it (console,MFC,Win32,many others).
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Press Keys
29 Oct, 2006 - 07:55 PM
Post #9

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
for example i press my assign letter from my keyboard then it excute the method that i aasign on it....

just example:

if i had a program...

with certain commands...and functions....
[q]uit
[p]layer
[s]elect

if i press q,p,s, or any.....on my declaration it exute the methods for that.....

This post has been edited by NyeNye: 30 Oct, 2006 - 09:00 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:02AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month