Archived

This topic is now archived and is closed to further replies.

Beyond getch()

This topic is 5600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know of a "getch()" that returns the KEYCODE (not the ASCII of the character the key displays) like JAVA''s "e.getKeyCode" or in BASIC "is it scancode()?". Anyway I need it for implementing key controls from the arrow keys so if you could help that would be cool . >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

And the Dark Lord shall DESTROY Middle Earth

And Ilthigore will save you

Share this post


Link to post
Share on other sites
They are definetely different. I wrote a simple C++ program to return the value of getch() and it was different to the values returned by my java test program for "e.getKeyCode()". Also in getch() all the arrow keys return the same value (someone correct ME if my program is corrupt, the JAVA one is definetely correct as I checked it with the keyCode example on www.java.sun.com). Also I've just started the project I need this info for and yet another question has arisen!

How do you get the following to work:

main.cpp:


      
#include "include.h"

main()
{
exampleClass example(...);
.
. //Class members are called.

.
return 0;
}





classes.cpp:


        
class exampleClass
{
public:
exampleClass(int);
exampleClass(exampleClass&);
void member1();
void member2();
.
. //The rest of the class.

.
};






members.cpp


        

exampleClass::exampleClass(int a){A=a;}

exampleClass::exampleClass(exampleClass&c){A=c.A;)

void exampleClass::member1()
{
.
.//member 1

.
}

void exampleClass::member2()
{
.
.//member2

.
}
....//other members




include.h:

  


#ifndef EXAMPLE_INCLUDE_H
#define EXAMPLE_INCLUDE_H

#include <iostream>
using namespace std
#include <stdlib.h>
#include <conio.h>
.
.//headers

.
#include "TheHeaderICantWorkOutHowToWrite.h"

#endif



The problem is I can't find a way to let main.cpp, class.cpp and members.cpp communicate with each other. If I just include the members in "TheHeader....Write.h" I get about 30 errors. I need to know how to write "TheHeaderICantWorkOutHowToWrite.h".

Thanks




>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

And the Dark Lord shall DESTROY Middle Earth


And Ilthigore will save you



[edited by - ilthigore on August 17, 2002 1:44:26 PM]

Share this post


Link to post
Share on other sites
if you include windows.h you can use GetAsyncKeyState().. it returns if the specified key has been pressed.
i.e.

if(GetAsyncKeyState(VK_ESCAPE))

Share this post


Link to post
Share on other sites
I searched windows.h for the VK_* definitions and I can''t find them although VK_LEFT doesn''t work. If someone could print a list of definitions for:

  • Left
  • Right
  • Up
  • Down
  • Control
  • Space
  • Return/Enter
  • Alt
  • Shift

That would be great. Also I notice the parameter type is int. Can you just use scan/key codes here to make life easier or not?

(note: If you answer the last question don''t bother with the definitions as I can use scancodes/keycodes fine)

Thanks for the help so far!



And the Dark Lord shall DESTROY Middle Earth


But Ilthigore will save you

Share this post


Link to post
Share on other sites
All virtual key code definitions are declared in winuser.h. And ASCII codes for letters and numbers are the same, if you dont believe me heres a snippet from winuser.h :


  

/*
* VK_0 - VK_9 are the same as ASCII ''0'' - ''9'' (0x30 - 0x39)
* 0x40 : unassigned
* VK_A - VK_Z are the same as ASCII ''A'' - ''Z'' (0x41 - 0x5A)
*/




Share this post


Link to post
Share on other sites
From MSDN: "When reading a function key or an arrow key, getch must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code."

Does that answer your question on the arrowkeys?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Ilthigore
They are definetely different. I wrote a simple C++ program to return the value of getch() and it was different to the values returned by my java test program for "e.getKeyCode()". Also in getch() all the arrow keys return the same value (someone correct ME if my program is corrupt, the JAVA one is definetely correct as I checked it with the keyCode example on www.java.sun.com). Also I''ve just started the project I need this info for and yet another question has arisen!



That''s because Java uses 16bit characters (UNICODE), C++ uses 6bit characters (ASCII).

Share this post


Link to post
Share on other sites