Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,047 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,532 people online right now. Registration is fast and FREE... Join Now!




Problem with WM_KEYUP

 
Reply to this topicStart new topic

Problem with WM_KEYUP

sjf123abc
5 Aug, 2008 - 03:43 AM
Post #1

New D.I.C Head
*

Joined: 23 Jul, 2008
Posts: 36


My Contributions
The problem is when I compile the program it does not read the up arrow key. When I press it, it sits there.


CODE
#include <iostream>
#include <ctime>
#include <conio.h>
#include <string>
#include <windows.h>
#include <winuser.h>
using namespace std;
int main()
{
int user;    

cin >> user;


if(user == WM_KEYUP)
{
     cout << "You pressed the up key" << endl;
}
    
  

    return 0;
}


This post has been edited by NickDMax: 5 Aug, 2008 - 07:10 AM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Problem With WM_KEYUP
5 Aug, 2008 - 07:15 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Well that is REALLY not how to use WM_KEYUP... cin reads in standard characters and will do nothing for special keys (Fn keys, ALT, CTRL, etc).

So, how do you detect arrow keys.

One solution is to use the conio.h -- not the best solution but it is often simple and. Since you seem to be on windows than using the window API is the natural solution.

see this old post for more info (sorry I don't have time to write a specific example and I have answered this question before).
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 05:12PM

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