Computer Science Canada

Turings input.keydown

Author:  omni [ Thu Jun 10, 2004 7:58 pm ]
Post subject:  Turings input.keydown

Alright, I've gotten used to Turing's syntax a lot. It seems to me that in C++ in order to use functions, you have to include libraries. Maybe I'm blind, but I can't find the parameters needed for other functions.

Anyways

Currently, the only command I know that can receive input is cin .
But that command waits, is there a command that will recieve input, but also continue on with the loop. EX; Turings Input.KeyDown.

Author:  McKenzie [ Thu Jun 10, 2004 8:22 pm ]
Post subject: 

Assuming you are developing in a Windows environment you keep track of the status of all of the keys yourself (array of bool). Windows will generate a message for both keydown and keyup and tell you which key. In the DOS environment it is similar but you have to use some assembly to get it to work (well at least with the last DOS compiler I used)

Author:  omni [ Thu Jun 10, 2004 8:50 pm ]
Post subject: 

ok, I understood part of what you said, I want to run in a Windows environment. So:

char key[256] // or was it 255 keys?

for (x=0,x =255,x++)
key[x]= ????

Is there an ord( function in C++?

Author:  Catalyst [ Thu Jun 10, 2004 9:36 pm ]
Post subject: 

this would be ur message handler

code:

LRESULT CALLBACK WndProc (HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_KEYDOWN:       
        keys[wParam] = true;                                   
        return 0;   
       
    case WM_KEYUP:       
        keys[wParam] = false;                                   
        return 0;                         
    default:
        return DefWindowProc (hWnd, message, wParam, lParam);
    }

Author:  wtd [ Fri Jun 11, 2004 12:47 am ]
Post subject: 

There's no need for things like "ord" in C++. Characters are integers. Just really small integers. Feel free to cats from char to int.

code:
char ch = 'A';
int i = static_cast<int>(ch);


: