Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Detect keypress count Pin
Luc Pattyn24-Dec-11 2:21
sitebuilderLuc Pattyn24-Dec-11 2:21 
GeneralRe: Detect keypress count Pin
CPallini24-Dec-11 3:59
mveCPallini24-Dec-11 3:59 
AnswerRe: Detect keypress count Pin
Luc Pattyn24-Dec-11 4:06
sitebuilderLuc Pattyn24-Dec-11 4:06 
GeneralRe: Detect keypress count Pin
CPallini24-Dec-11 4:42
mveCPallini24-Dec-11 4:42 
QuestionRe: Detect keypress count Pin
David Crow23-Dec-11 9:28
David Crow23-Dec-11 9:28 
AnswerRe: Detect keypress count Pin
Gary R. Wheeler23-Dec-11 23:56
Gary R. Wheeler23-Dec-11 23:56 
AnswerRe: Detect keypress count Pin
Lactoferrin24-Dec-11 1:45
Lactoferrin24-Dec-11 1:45 
AnswerRe: Detect keypress count Pin
Software_Developer24-Dec-11 4:54
Software_Developer24-Dec-11 4:54 
Ths code does just what you asked for.

Ok, the timing is not well..... just press the keys down rapidly to get a good time measure. Laugh | :laugh:

C#
#include <windows.h>
#include <iostream>
#include <time.h>
#include <cmath>
using namespace std;

int main(int argc, char *argv[])
{

	HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);//handle to input
	INPUT_RECORD ir;//keyevent structure
	DWORD dwRead = 0;//dummy....forget this for now
	bool bLoop = true;//continue or quit?
	clock_t timer_start, timer_stop;
	int Number_of_Keypresses=0;

	ZeroMemory(&ir,sizeof(INPUT_RECORD));//clear the memory before starting
	//cout << "Press arrow keys......escape to quit" << endl;
	timer_start = clock ();
	timer_stop = clock ();

	while(bLoop)
	{
		
		if( ReadConsoleInput( hInput,&ir,1,&dwRead) )
		{ 

			if(ir.EventType == KEY_EVENT ) 	
			{
				if(ir.Event.KeyEvent.bKeyDown )//is it a key?   
				{
					//Is the key down or up?
					timer_start = clock ();
					Number_of_Keypresses++;

						switch(ir.Event.KeyEvent.wVirtualKeyCode)
						{//What was the key?
							case VK_DOWN:
							cout << "DOWN" << endl;
							break;
							case VK_UP:
							cout << "UP" << endl;
							break;
							case VK_RIGHT:
							cout << "RIGHT" << endl;
							break;
							case VK_LEFT:
							cout << "LEFT" << endl;
							break;
							case VK_ESCAPE:
							bLoop = false;//Quit
							default:
							break;

						}  //switch
					

				} //bKeyDown
				else 
				{
				  
				  timer_stop = clock ();timer_start = clock ();
				}
                cout <<"Number_of_Keypresses = "<< Number_of_Keypresses<<"\n";
				cout <<"Millisecond delay = "<<abs(timer_start - timer_stop )  <<" (from KEY_EVENT_keydown to KEY_EVENT_KeyUp)" << endl;
				cout <<"______________________________________________________\n";
			} //EventType

		}//read
	}//while
return 0;
}

QuestionHow GetObjectSchema() to work ? Pin
André Dewispelaere23-Dec-11 3:43
André Dewispelaere23-Dec-11 3:43 
AnswerRe: How GetObjectSchema() to work ? Pin
Mohibur Rashid26-Dec-11 22:13
professionalMohibur Rashid26-Dec-11 22:13 
QuestionHow to Delete A Node with its all Child in XML File ? Pin
002comp22-Dec-11 23:18
002comp22-Dec-11 23:18 
AnswerRe: How to Delete A Node with its all Child in XML File ? Pin
CPallini22-Dec-11 23:40
mveCPallini22-Dec-11 23:40 
AnswerRe: How to Delete A Node with its all Child in XML File ? Pin
jschell23-Dec-11 10:01
jschell23-Dec-11 10:01 
QuestionFinding an item in linked list (CList) Pin
VCProgrammer22-Dec-11 19:00
VCProgrammer22-Dec-11 19:00 
AnswerRe: Finding an item in linked list (CList) Pin
Richard MacCutchan22-Dec-11 22:45
mveRichard MacCutchan22-Dec-11 22:45 
SuggestionRe: Finding an item in linked list (CList) Pin
David Crow23-Dec-11 3:35
David Crow23-Dec-11 3:35 
GeneralRe: Finding an item in linked list (CList) Pin
Richard MacCutchan23-Dec-11 4:46
mveRichard MacCutchan23-Dec-11 4:46 
AnswerRe: Finding an item in linked list (CList) Pin
smileangle27-Dec-11 13:37
smileangle27-Dec-11 13:37 
QuestionHeap error on std::string deletion from local function Pin
Fred Ackers22-Dec-11 1:04
Fred Ackers22-Dec-11 1:04 
AnswerRe: Heap error on std::string deletion from local function Pin
Chris Losinger22-Dec-11 1:34
professionalChris Losinger22-Dec-11 1:34 
GeneralRe: Heap error on std::string deletion from local function Pin
Fred Ackers22-Dec-11 9:33
Fred Ackers22-Dec-11 9:33 
GeneralRe: Heap error on std::string deletion from local function Pin
Chris Losinger22-Dec-11 9:55
professionalChris Losinger22-Dec-11 9:55 
GeneralRe: Heap error on std::string deletion from local function Pin
Fred Ackers22-Dec-11 10:44
Fred Ackers22-Dec-11 10:44 
AnswerRe: Heap error on std::string deletion from local function Pin
Erudite_Eric22-Dec-11 4:28
Erudite_Eric22-Dec-11 4:28 
AnswerRe: Heap error on std::string deletion from local function Pin
Erudite_Eric23-Dec-11 23:48
Erudite_Eric23-Dec-11 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.