How to detect special keys using c++

This is a discussion on How to detect special keys using c++ within the C++ Programming forums, part of the General Programming Boards category; As we know, each character has a unique ASCII code, which can be used to detect it even if the ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    79

    How to detect special keys using c++

    As we know, each character has a unique ASCII code, which can be used to detect it even if the character itself is not available on a standard keyboard. Similarly, my task is to detect special keys such as F1, F2, <--, -->,Shift+tab etc. when they are pressed, which in fact give an ASCII code of zero if we try it out. Is there any way? Please help me out here.

    e.g. if F1 is pressed then perform required tasks...

    Compiler:Borland C++ 5.0
    Last edited by sundeeptuteja; 07-09-2002 at 03:05 AM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Here's a poor attempt for you to ponder over. It takes the wild assumption that you are using a Windows console.
    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    int main(void){	
    	
    	int pressedkey;
    	int i = 0;
    	
    	cout << "Press any key." <<endl;
    	while (1) 
    	{
    		if ((pressedkey = getch()) != EOF)
    		{
    			cout <<i++ <<" " <<hex <<pressedkey <<endl;
    		}
    	}
    	return 0;
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ToUnicodeEx and dead keys inside system wide hooks
    By RevengerPT in forum Windows Programming
    Replies: 1
    Last Post: 08-13-2009, 03:51 PM
  2. Simulate Keys with a Keyboard Hook
    By guitarist809 in forum Windows Programming
    Replies: 3
    Last Post: 11-14-2008, 08:14 PM
  3. special function detection
    By zyd in forum C Programming
    Replies: 7
    Last Post: 02-28-2006, 03:25 PM
  4. Replies: 5
    Last Post: 11-20-2003, 01:27 AM
  5. how to detect multimedia keys
    By kwazar in forum Windows Programming
    Replies: 1
    Last Post: 01-25-2003, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21