AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Keyboard Hook

Ein Thema von danten · begonnen am 4. Mär 2012 · letzter Beitrag vom 1. Feb 2017
Antwort Antwort
Seite 1 von 2  1 2      
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#1

Keyboard Hook

  Alt 4. Mär 2012, 14:16
Hello
I have a problem with the application.
I created a Keyboard Hook and wants to work on another computer than just for me.
Can you please help.

Delphi-Quellcode:
type
  TMainForm = class(TForm)
    lbl: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  end;

var
  MainForm: TMainForm;
  MainHook : HHOOK;
  Wnd1,Wnd2 : array[0..255] of char;

implementation

{$R *.dfm}

function GetCapsLockStatus: Integer;
begin
   Result := GetKeyState(VK_CAPITAL);
end;

function KeyboardHook(Code: Integer; wParam : WPARAM;
  lParam : LPARAM): Longint; stdcall;
var
  Buffer : TEventMsg;

  procedure TranslateKey(Key : Byte);
  begin
    if (Key <> VK_LBUTTON) and (Key <> VK_RBUTTON) then
    begin
      GetWindowText(GetForegroundWindow, Wnd2, SizeOf(Wnd2));
      if wnd1 <> wnd2 then
    begin
      Wnd1 := Wnd2;
    end;
    end;
    with MainForm do
    begin
      case Key of
        VK_RETURN : lbl.Caption := ('[Enter]');
        VK_BACK : lbl.Caption := ('[Backspace]');
        VK_ESCAPE : lbl.Caption := ('[Esc]');
        VK_SHIFT : lbl.Caption := ('[Shift]');
        VK_MENU : lbl.Caption := ('[Alt]');
        VK_CONTROL : lbl.Caption := ('[Ctrl]');
        VK_DELETE : lbl.Caption := ('[Delete]');
        VK_SPACE : lbl.Caption := ('[SPACE]');
        VK_NUMLOCK : lbl.Caption := ('[NumLock]');
        VK_SEPARATOR : lbl.Caption := ('[Separator]');
        VK_SUBTRACT : lbl.Caption := ('[Subtract]');
        VK_DECIMAL : lbl.Caption := ('[Decimal]');
        VK_DIVIDE : lbl.Caption := ('[Divide]');
        VK_SCROLL : lbl.Caption := ('[Scroll]');
        VK_LSHIFT : lbl.Caption := ('[Left Shift]');
        VK_RSHIFT : lbl.Caption := ('[Right Shift]');
        VK_LCONTROL : lbl.Caption := ('[Left Control]');
        VK_RCONTROL : lbl.Caption := ('[Right Control]');
        VK_LMENU : lbl.Caption := ('[Left Menu]');
        VK_RMENU : lbl.Caption := ('[Right Menu]');
        VK_PLAY : lbl.Caption := ('[Play]');
        VK_ZOOM : lbl.Caption := ('[Zoom]');
        VK_LBUTTON : lbl.Caption := ('[Left mouse button]');
        VK_RBUTTON : lbl.Caption := ('[Right mouse button]');
        VK_CANCEL : lbl.Caption := ('[Control-break processing]');
        VK_MBUTTON : lbl.Caption := ('[Rolout mouse button]');
        VK_TAB : lbl.Caption := ('[Tab]');
        VK_CLEAR : lbl.Caption := ('[Clear]');
        VK_PAUSE : lbl.Caption := ('[Pause]');
        VK_CAPITAL : lbl.Caption := ('[CapsLock]');
        VK_PRIOR : lbl.Caption := ('[Page UP]');
        VK_NEXT : lbl.Caption := ('[Page DOWN]');
        VK_END : lbl.Caption := ('[End]');
        VK_HOME : lbl.Caption := ('[Home]');
        VK_LEFT : lbl.Caption := ('[Left]');
        VK_RIGHT : lbl.Caption := ('[Right]');
        VK_UP : lbl.Caption := ('[Up]');
        VK_DOWN : lbl.Caption := ('[Down]');
        VK_SELECT : lbl.Caption := ('[Select]');
        VK_PRINT : lbl.Caption := ('[Print]');
        VK_EXECUTE : lbl.Caption := ('[Execute]');
        VK_SNAPSHOT : lbl.Caption := ('[Print Screen]');
        VK_INSERT : lbl.Caption := ('[Ins]');
        VK_HELP : lbl.Caption := ('[Help]');
        VK_F1 : lbl.Caption := ('[F1]');
        VK_F2 : lbl.Caption := ('[F2]');
        VK_F3 : lbl.Caption := ('[F3]');
        VK_F4 : lbl.Caption := ('[F4]');
        VK_F5 : lbl.Caption := ('[F5]');
        VK_F6 : lbl.Caption := ('[F6]');
        VK_F7 : lbl.Caption := ('[F7]');
        VK_F8 : lbl.Caption := ('[F8]');
        VK_F9 : lbl.Caption := ('[F9]');
        VK_F10 : lbl.Caption := ('[F10]');
        VK_F11 : lbl.Caption := ('[F11]');
        VK_F12 : lbl.Caption := ('[F12]');
        VK_F13 : lbl.Caption := ('[F13]');
        VK_F14 : lbl.Caption := ('[F14]');
        VK_F15 : lbl.Caption := ('[F15]');
        VK_F16 : lbl.Caption := ('[F16]');
        VK_F17 : lbl.Caption := ('[F17]');
        VK_F18 : lbl.Caption := ('[F18]');
        VK_F19 : lbl.Caption := ('[F19]');
        VK_F20 : lbl.Caption := ('[F20]');
        VK_F21 : lbl.Caption := ('[F21]');
        VK_F22 : lbl.Caption := ('[F22]');
        VK_F23 : lbl.Caption := ('[F23]');
        VK_F24 : lbl.Caption := ('[F24]');
        188 : lbl.Caption := ',';
        192 : lbl.Caption := '`';
        222 : lbl.Caption := Chr(39);
        220 : lbl.Caption := '';
        219 : lbl.Caption := '[';
        221 : lbl.Caption := ']';
        186 : lbl.Caption := ';';
        191 : lbl.Caption := '/';
        190 : lbl.Caption := '.';
        187 : lbl.Caption := '=';
        189 : lbl.Caption := '-';
        65 : lbl.Caption := 'a';
        66 : lbl.Caption := 'b';
        67 : lbl.Caption := 'c';
        68 : lbl.Caption := 'd';
        69 : lbl.Caption := 'e';
        70 : lbl.Caption := 'f';
        71 : lbl.Caption := 'g';
        72 : lbl.Caption := 'h';
        73 : lbl.Caption := 'i';
        74 : lbl.Caption := 'j';
        75 : lbl.Caption := 'k';
        76 : lbl.Caption := 'l';
        77 : lbl.Caption := 'm';
        78 : lbl.Caption := 'n';
        79 : lbl.Caption := 'o';
        80 : lbl.Caption := 'p';
        81 : lbl.Caption := 'q';
        82 : lbl.Caption := 'r';
        83 : lbl.Caption := 's';
        84 : lbl.Caption := 't';
        85 : lbl.Caption := 'u';
        86 : lbl.Caption := 'v';
        87 : lbl.Caption := 'w';
        88 : lbl.Caption := 'x';
        89 : lbl.Caption := 'y';
        90 : lbl.Caption := 'z';
        VK_NUMPAD0 : lbl.Caption := '0';
        VK_NUMPAD1 : lbl.Caption := '1';
        VK_NUMPAD2 : lbl.Caption := '2';
        VK_NUMPAD3 : lbl.Caption := '3';
        VK_NUMPAD4 : lbl.Caption := '4';
        VK_NUMPAD5 : lbl.Caption := '5';
        VK_NUMPAD6 : lbl.Caption := '6';
        VK_NUMPAD7 : lbl.Caption := '7';
        VK_NUMPAD8 : lbl.Caption := '8';
        VK_NUMPAD9 : lbl.Caption := '9';
        48 : lbl.Caption := 'é';
        49 : lbl.Caption := '+';
        50 : lbl.Caption := 'ě';
        51 : lbl.Caption := 'š';
        52 : lbl.Caption := 'č';
        53 : lbl.Caption := 'ř';
        54 : lbl.Caption := 'ž';
        55 : lbl.Caption := 'ý';
        56 : lbl.Caption := 'á';
        57 : lbl.Caption := 'í';
      end;

    if GetCapsLockStatus > 0 then
    begin
     lbl.Caption := AnsiUpperCase(lbl.Caption);
    end else
    begin
     lbl.Caption := AnsiLowerCase(lbl.Caption);
    end;
  end;
  end;

begin
  Result := 0;
  Buffer := PEventMsg(lParam)^;

  if Buffer.Message = WM_KEYDOWN then
  begin
    TranslateKey(Buffer.paramL);
  end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  MainHook := SetWindowsHookEx(WH_JOURNALRECORD, KeyboardHook, hInstance, 0);
  MainForm.Icon := Application.Icon;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
  UnhookWindowsHookEx(MainHook);
end;
Daniel
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

AW: Keyboard Hook

  Alt 4. Mär 2012, 14:25
I created a Keyboard Hook and wants to work on another computer than just for me.
Sorry but I don't understand what you mean esspecially the part after the "and" does not make any sense to me.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: Keyboard Hook

  Alt 4. Mär 2012, 14:26
Could u give us more details on "i have a problem"?
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#4

AW: Keyboard Hook

  Alt 4. Mär 2012, 14:33
When I run the program on a PC with Windows XP, the program does not work.
When I run the program on a PC with Windows 7, the program does not work.
When I run the program in VirtualBox, so also does not work.
When I run programv computer where I created it, so it works perfectly.
Angehängte Dateien
Dateityp: 7z KeyHook.7z (10,7 KB, 44x aufgerufen)
Daniel

Geändert von danten ( 4. Mär 2012 um 14:45 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.026 Beiträge
 
Delphi 12 Athens
 
#5

AW: Keyboard Hook

  Alt 4. Mär 2012, 15:05
http://www.delphipraxis.net/93871-ve...exthookex.html ?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#6

AW: Keyboard Hook

  Alt 4. Mär 2012, 15:29
Thank you, but I do not want to use external DLLs.
It would not write my code to make it work without DLL?

Please show the code or modify my code.
Daniel
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#7

AW: Keyboard Hook

  Alt 4. Mär 2012, 15:45
if u want to have a global keyhook u have to use a dll. there is no alternative!
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#8

AW: Keyboard Hook

  Alt 4. Mär 2012, 16:22
Sorry, I somehow do not understand.
Creating a program for creating tutorials and sample code from one part.
It shows users what button was pressed the keyboard.

I do not do any program on stealing data from the computer as some keylogery.

Very please someone who has the time to download the attachment KeyHook.7z above and added a piece of code to me so angry.
For you, it's a matter of a few lines and I did a lot of help in further work.

Thank you for your help.
Daniel

Geändert von danten ( 4. Mär 2012 um 18:45 Uhr) Grund: request for a big help - desperation
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#9

AW: Keyboard Hook

  Alt 4. Mär 2012, 18:58
if u want to have a global keyhook u have to use a dll. there is no alternative!
That is not quite correct. It depends on the hook type. Some global hooks don't need a DLL.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#10

AW: Keyboard Hook

  Alt 4. Mär 2012, 19:18
if u want to have a global keyhook u have to use a dll. there is no alternative!
That is not quite correct. It depends on the hook type. Some global hooks don't need a DLL.
We are talking about a global hook for the Keyboard ... not about some hooks
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:11 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