Autor Beitrag
JacK_Silent
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: So 28.05.06 23:11 
Hi @ all


1.Problem:

ich hab folgenen Quellcode für einen DLL Datei gefunden

:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
library KeyboardHook;

uses 
  Windows, 
  SysUtils, 
  Classes; 

{$R *.res} 

type 
  TKeybDLLHookStruct = packed record 
    vkCode: integer; 
    scanCode: integer; 
    flags: integer; 
    time: integer; 
    dwExtraInfo: integer; 
  end
  PKeybDLLHookStruct = ^TKeybDLLHookStruct; 

const 
  WH_KEYBOARD_LL = 13

var 
  hKeyHook: THandle; 


function KeyboardProc_LowLevel(code: integer; wParam,   lParam: Integer): integer; stdcall
var 
  P: PKeybDLLHookStruct; 
  KeyDown: Boolean; 
begin 
  if Code < 0 then 
    result := CallNextHookEx(hKeyHook, Code, wParam, lParam) 
  else 
  begin 
    P := Pointer(lParam); 
    KeyDown := P^.flags = 0

    if KeyDown and (P^.vkCode = VK_RWIN) and
      Bool($8000 and GetAsyncKeyState(VK_LWIN)) then
      result := HC_SKIP
    else result := CallNextHookEx(hKeyHook, Code, wParam, lParam); 

  end
end;

procedure StartHook; 
begin 
  hKeyHook := SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc_LowLevel, HInstance, 0); 
end

procedure StopHook; 
begin 
  UnhookWindowsHookEx(hKeyHook); 
end

exports 
  StartHook, 
  StopHook; 
  
begin 
end.


Mein Problem besteht drain, dass die Windows Tasten nich gesperrt werden!

Wenn ich jedoch ein or setze, wird die Windows Taste zwar gesperrt, mit ihr jedoch auch die ganze restliche Tastatur!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
     if KeyDown and (P^.vkCode = VK_RWIN) or
      Bool($8000 and GetAsyncKeyState(VK_LWIN)) then
      result := HC_SKIP
    else result := CallNextHookEx(hKeyHook, Code, wParam, lParam);


2.Problem:

Kann man den Quellcode der DLL Datei mit in die exe Datei integrieren? Wenn ja wie?


Zuletzt bearbeitet von JacK_Silent am Mo 29.05.06 14:41, insgesamt 1-mal bearbeitet
Tobi482
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135



BeitragVerfasst: Mo 29.05.06 14:40 
Hi,

1. Problem:

bin auch kein Fachmann in Sachen Hook, jedoch muss CallNextHookEx IMMER ausgeführt werden. Dieser Befehl übergibt die gehookte Informaion an den, wenn vorhandenen, nächsten Hook in der Hookchain.
Wenn ich deinen Code richtig verstehe möchtest du, wenn einebestimmte Taste gedrückt wird, dafür sorgen, dass diese WindowsMessage nie ihr Ziel erreicht.
Ich weiß nicht, ob das Unterdrücken der Hookchain der richtige weg ist.
Wie wäre es, wenn du eine einadere Msg weiter schicksts, wenn dein Hook ne Msg kriegt. Am besten eine, die keine Reaktion verursacht.

z.B. du willst A-Taste blocken

Ablauf:
- A-KeyDown-Msg wird an Prog gesendet
- dein Hook fängt sie ab
- dein Hook macht daraus ne neue Msg z.B. WM_USER+1000 (nicht belegt)
- übergibt sie nun weiter an die restlichen Hooks
- WM_USER+1000 erreicht Opfer-Prozess anstatt A-KeyDown-Msg

dann kreigt das Opfer-Programm jedesmal wenn du A drückst immer so ein "inhaltsloses" Paket.

Bitte vergiss nicht das mehrere Msg gesendet weden pro Knopf. 2-3 glaube ich KeyDown, Keypress, KeyUp oder so ähnlich fang lieber alle ab.

2. Problem

Nein kann man nicht. Da du möchtest, dass dein Hook immer ausgeführt wird solange das Prog läuft und nicht nur dann, wenn es auf den Focus hat, musst du einen globalen Hook benutzten. Globale Hooks wie der WH_Keyboard müssen in eine DLL.

Korrigiert mich, wenn ich Mist erzähle, wie gsagt bin kein Hook Profi.

Gruß Tobi
JacK_Silent Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Mo 29.05.06 15:17 
Kannst du mir erklären wie man aus dem Hook eine neue Msg macht??
Funktioniert das auch mit der Windows Taste?


Übrigens funktioniert der Quellcode so weit! Aber die Windows Taste lässt sich halt nicht überspringen.

sperrt z.B. die Numpad 0 Taste:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
     
if KeyDown and (P^.vkCode = VK_NUMPAD0) then  
result := HC_SKIP  
else result := CallNextHookEx(hKeyHook, Code, wParam, lParam);
Tobi482
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135



BeitragVerfasst: Mo 29.05.06 15:21 
Hi,

Code, wParam, lParam

Dies sind die Paramter die bestimmen was der Inhalt der NAchricht ist. Änder sie so um, dass kein Tastendrück übergeben wird.

Wenn ich mich recht erinnere dann ist wParam {keydown keyup, keypress} und lParam der key. bin mir da aber nicht sicher musst etwas mit rum spielen.

Gruß Tobi

Nachtrag:

Ups habs vergessen^^ Alt, Tab, WinKey sind keine Keydown befehle sonder spezielle System-bla-bla-bla (namen vergessen^^).

Win-Key sendet kein Keydown sondern ein anderes Signal, genau so wie ALT-Key. Musst dich da mal in der MSDN schaul lesen. auch Tasten Kombinationen senden solche spezial Signale z.B. ALT+F4, ALT+TAB, CTRL+RETURN
JacK_Silent Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Mo 29.05.06 16:38 
SYSKEYDOWN, SYSKEYDUP??

funzt au net!
er compiliert zwar die DLL aber das Starmenü öffnet sich immer noch!

msdn.microsoft.com/l...evelkeyboardproc.asp

kann man damit evtl was anfangen??
msdn.microsoft.com/l...lrfkeystateflags.asp
Tobi482
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135



BeitragVerfasst: Mo 29.05.06 16:48 
Hi,

also vermutlich wird dein Hook zwar alamiert, aber das signal ist schon durch. Das Problem habe ich auch. Wie gesagt ich bin kein Profi im Thema Hook.

GENAU: WM_SYSKEYDOWN, WM_SYSKEYDUP das waren die namen die ich net mehr wusste :-D

Schau die mal meine Frage zum Thema Hooks an (ein paar einträge tiefer).

Es gibt mehrere hook-typen, vor dem verarbeitetn, nach dem verarbeiten, hoch, runter links, recht. für jeden mist gibts n hook ich versteh das aber auch nicht^^.

Hier noch was gegen den AFFENGRIFF weiß net ob das geht hab ich gerade gefunden

Zitat:

Hey Owlet,

I think you approching the problem wrongly, in that there are functions that you can use for this problem. Now i cant check this code casue im on XP and stopping alt+tab and start menu on xp is alot harder than it was before. But this code stops control alt and del and i think alt+tab and winkey as well, atleast when i made a security prog a few years back i used somthing like this code and it worked but try this it should work:

SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, 0, 0); //Turn Off Crtl+alt+del

SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, 0, 0); //Turn On Crtl+alt+del

HIER LESEN

That may not be the one for alt tab, but i do know that the function for turning off alt and tab will also turn off the winkey. Try that though.


Gruß Tobi
JacK_Silent Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Mo 29.05.06 17:21 
ausblenden Delphi-Quelltext
1:
2:
3:
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 100); //Turn Off Crtl+alt+del 

SystemParametersInfo(SPI_SCREENSAVERRUNNING, 000); //Turn On Crtl+alt+del


das simuliert nur den Bildschirmschoner, wo man bekanntlicherweise Crtl+alt+del net drücken kann!

Gibt es denn eine andere Möglichkeit die Windowstaste zu sperren? Vielleicht mit ner andere Prozedur oder einer andere Funktion? Hat jemand eine Idee?
sztojka
Hält's aus hier
Beiträge: 1



BeitragVerfasst: So 11.06.06 12:05 
das funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
...
KeyDown := P^.flags = 1;

    if KeyDown and (P^.vkCode = VK_LWIN) then
      result := HC_SKIP
...


sZTojKa

Moderiert von user profile iconNarses: Quote- durch Delphi-Tags ersetzt
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 11.06.06 13:05 
Ich möchte nochmal was anderes dazu sagen:
Wenn ich mich jetzt nicht vertue dann kann man den LowLevel hook doch auch in einer EXE haben und muss es nicht extra in eine dll auslagern. Das muss doch für WH_KEYBOARD gemacht werden. Ausserdem funzt der LL Param nur unter NT Systemen.

msdn.microsoft.com/l...setwindowshookex.asp

Vielleicht hilft dir dsas ja weiter das Programm bisschen zu optimieren.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Sa 25.04.09 13:32 
Wie kann ich denn dann ein KeyDown mit dem WinKey als Parameter an das System senden? (siehe mein Thema 91799)