Beyond getch()

Started by
7 comments, last by Ilthigore 21 years, 8 months ago
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

>>>>>>>>>>>>>>>>>Ilthigore<<<<<<<<<<<<<<<<<
Advertisement
I''m not sure, but aren''t the keycodes the same as the ascii codes, except for letters, where they are always the value of an uppercase. Someone correct me if I''m wrong...



Those who do not love don''t live.



[MSDN|Google|Bloodshed|My lousy page|email.me]
[My Lousy Page | Kings Of Chaos | Vampires | [email=lordlethis@hotmail.com]email.me[/email]]
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]
>>>>>>>>>>>>>>>>>Ilthigore<<<<<<<<<<<<<<<<<
if you include windows.h you can use GetAsyncKeyState().. it returns if the specified key has been pressed.
i.e.

if(GetAsyncKeyState(VK_ESCAPE))
-Your human mentality screams for vengeance and thrives on the violence that you say you can hardly endure...
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

>>>>>>>>>>>>>>>>>Ilthigore<<<<<<<<<<<<<<<<<
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) */  


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?
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
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).
erm, 8bit, not 6bit ^_^

This topic is closed to new replies.

Advertisement