Bueno es para saber si las librerias estan bien, saber porque no verifica el estado de la tecla y saber si esta bien poner getasynckeystate fuera del main.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//#define OK -32767
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int tecla;
for(tecla=4 ; tecla<256 ; tecla++){
if(GetAsyncKeyState(tecla) > 0){
printf("Presiono la tecla %c", tecla);
}
}
/*
int main(int argc, char *argv[]) {
return 0;
}
*/
Todo código debe estar dentro de una función.
Si lo pongo asi:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define OK -32767
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void get(){
int tecla;
for(tecla=4 ; tecla<256 ; tecla++){
if(GetAsyncKeyState(tecla) == OK){
printf("Presiono la tecla %c", tecla);
}
}
}
int main(int argc, char *argv[]) {
get();
return 0;
}
El preblema es que getasynckeystate() no funciona, el programa se habre pero no muestra ningun mensaje y no se si poner una constante diferente en el if().
porque el programa corre una sola vez y está procesando otros mensajes probablemente... recomiendo antes de intentar hacer algo, aorender a programar bien en el lenguaje y entender todos los conceptos basicos
Bueno, gracias por la ayuda ya lo analice bastante y me fije que la funcion getasynckeystate() verifica el estado de las teclas internamente y que por tal motivo es imposible que muestre el mensaje cuando una tecla se pulsa, cuando el bucle se inicia getasynckeystate verfica que ninguna tecla fue pulsada luego salta y pasa a la siguiente iteraccion y asi va hasta que se termine el bucle.
Tendrías que aprender a programar primero antes de intentar hacer un keylogger, luego documentarte acerca de las APIs de Windows y recién ahí comenzar a armar tu programa deseado...
De todas formas te dejo la solución porque estaba aburrido... :silbar:
#include<windows.h>
#include<cstdio>
int main(){
register int iTecla;
BOOL bRun=TRUE;
while(bRun){
for(iTecla^=iTecla;iTecla<256;iTecla++){
if(GetAsyncKeyState(iTecla)&1){
if(iTecla==VK_ESCAPE)
bRun=FALSE;
printf("La tecla virtual numero %i fue presionada...\n",iTecla);}}
Sleep(17);}
return 0;}
B#