-
Try using Borland's command-line compiler (in the second table on that linked page named "Compiler"). It is free and works very well, but you may not be too keen on it because the free version includes no IDE. Iow, you have to compile by typing a command line. It's actually the only compiler I use except when the situation requires otherwise.
Good luck to you.
-
>LuckY, what compiler do you use? (I use dev-c++) the code you gave me doesnt run...
Change cprintf to printf. It compiles fine under Dev-C++ after making that change.
-
Ok, now LuckY's program works, but it returns the same values as the number keys (the ones above the letters). I need to know how to tell when and what numpad keys are pressed. Im kind of in a rush, this is due on Friday...
-
That's only possible using GetAsyncKeyState, a function from windows.h. Or by having a full message loop, but then you can't use the Windows console anymore.
-
Im already using GetAsyncKeyState. How do I know when the numpad keys?
At this point im going to put up my code, so everyone can see what im doing. You don't have to take it and edit it and spit it back out. Infact, please don't. I would rather learn how to do it than have someone do it for me.
Code:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define SHIFTED 0x8000
//define variables
int LEFT; int RIGHT; int UP; int DOWN;
int LSHIFT; int RSHIFT;
int ENTER;
int LALT; int RALT;
int PRESSED;
int scale;
int main ( void ){
//set arrow-key keycodes
LEFT=37; RIGHT=39; UP=38; DOWN=40;
//set shift keycodes
LSHIFT=160; RSHIFT=161;
//set enter keycode
ENTER=13;
//set alt keycodes
LALT=164; RALT=165;
//set key-pressed value
PRESSED=-32767;
//set default movement scale
scale=2;
//define cursor point
POINT XY;
//print instructions
cout<<"Use the arrow keys to move the cursor, hold SHIFT to move the cursor faster."<<endl;
cout<<"Press ENTER to left-click, and ALT to right-click."<<endl;
//main loop
while(1==1)
{
//if enter pressed then left-click
if(GetAsyncKeyState(ENTER)==PRESSED){
mouse_event(MOUSEEVENTF_LEFTDOWN, XY.x, XY.y, 0, 0);
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP, XY.x, XY.y, 0, 0);
}
//if alt pressed then right-click
if(GetAsyncKeyState(LALT)==PRESSED||GetAsyncKeyState(RALT)==PRESSED){
mouse_event(MOUSEEVENTF_RIGHTDOWN, XY.x, XY.y, 0, 0);
Sleep(100);
mouse_event(MOUSEEVENTF_RIGHTUP, XY.x, XY.y, 0, 0);
}
//move mouse with arrow keys. set scale to 10 if shift is pressed, else 2
if(GetAsyncKeyState(LEFT)==PRESSED){
if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
scale=10;
}else{
scale=2;
}
GetCursorPos( &XY );
SetCursorPos( XY.x - scale, XY.y);
}
if(GetAsyncKeyState(RIGHT)==PRESSED){
if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
scale=10;
}else{
scale=2;
}
GetCursorPos( &XY );
SetCursorPos( XY.x + scale, XY.y);
}
if(GetAsyncKeyState(UP)==PRESSED){
if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
scale=10;
}else{
scale=2;
}
GetCursorPos( &XY );
SetCursorPos( XY.x, XY.y - scale );
}
if(GetAsyncKeyState(DOWN)==PRESSED){
if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
scale=10;
}else{
scale=2;
}
GetCursorPos( &XY );
SetCursorPos( XY.x, XY.y + scale );
}
}
return 0;
}
-
http://msdn.microsoft.com/library/de...alKeyCodes.asp
Lists all the valid parameters to GetAsyncKeyState. There are VK_NUMPADn constants there, too.