473,770 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking for "key pressed" in C++?

Hi!

What is the best way to check whether a key is pressed without blocking
in C++?

I know I can use cin.get(c) to get a character from standard input, but
this blocks.

And I know _kbhit() exists in MSVC++, but that's in <conio.h> and
probably not standard, is it?

I need a way to say:
1. do something
2. check if a key was pressed
3. if no key was pressed, go to 1.
4. if a key WAS pressed, continue with 5.
5. the rest of the program

Thanks in advance for any hints!

Koen
Jul 19 '05 #1
0 6870

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16317
by: Byron McClain | last post by:
.... is being consumed. I added an event handler for the "keypress" event and my delegate never gets executed. Why? I am trying to catch the "enter" key pressed event to prevent the DataGrid from going to currentRow + 1. Instead I want it to give focus to the next cell (currentCol + 1) to the right if not at the end of the row. Example:
3
1949
by: rh | last post by:
I have a Button on a WinForm that has a text property = "&Submit". I noticed that whenever I pressed the "S" key only (without pressing the "Alt" key) the Button's click event would fire. I thought that it was only supposed to fire if the combo "Alt+S" was pressed. My problem is that I have another control (a DataGrid) that is suppoed to respond to the "S" key being pressed and I don't want the Button's click event to be fired. I only...
2
7214
by: Cindy | last post by:
Hi all you smarties out there, I'm having a little conundrum with my asp.net page Scenario: I have a form (asp.net) with no code behind (as yet). I have placed a javascript function on a server side textbox control to do something - eg change the words on label - when the key pressed is the "enter" key. I can see the label change to what i expect ----- BUT .... then the
4
5860
by: Mike R | last post by:
Hi, Could someone give me a pointer to do the following: I would like to capture a keystroke from "anywhere" , i.e If the user is in Word, Excel, Myother app, desktop etc... and they press CTRL+F12 I would like to capture this, pass it to my app and process my sub/function dependant on the keystroke. Thanks for any pointers
2
21267
by: Prabhudhas Peter | last post by:
How to Detect the "TAB" Key is pressed in the Text Box or Combo Box.... Which events catches the TAB key... I Want to perform some operations when the "TAB" key is pressed... -- Peter...
2
26588
by: Juan Martinez | last post by:
In a form i have a drawing control called VectorDraw and a textbox. The text box is disable, when i am using the drawing area i can write some text, what i want to do is that when i press any key that key show in the textbox, or if other control has the focus and i press other key also show in the textbox. I saw some info about this using the user32.dll like this: static extern bool TranslateMessage( ref Message lpMsg);
2
1646
by: moondaddy | last post by:
I writing a WPF windows app in c# and want to determine if the user has pressed the control key and the 'c' key at the same time similar to the standard windows 'copy' shortcut keys. How would I go about this? Thanks. -- moondaddy@noemail.noemail
11
12409
by: gnortenjones | last post by:
I have a linked table (to an oracle db), and I am trying to run a simple update query against it to change some data, but I am getting the following error: "...didn't update 0 fields due to a type conversion failure, 24 records due to key violations, 0 records due to lock violations..." The table I'm updating has 4 primary key's, and I'm trying to update the data in one of them. The data I'm updating shouldn't violate the uniqueness of...
5
4580
by: JamesX | last post by:
I am having trouble detecting if "down" or "up" key is pressed within a textbox. Evidently those keys do not fire the "KeyPressed" event. Does anyone know how to detect when they are pressed?
0
10237
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
10071
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
10017
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
9882
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...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
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...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
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
3589
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.