Autor Beitrag
Wotan89
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Sa 10.11.07 23:21 
Ich hab ein Problem mit einer booleanvariable(switch), welche dauernd auf false geschalten wird. Vielleicht ist mein Quelltext verkehrt.
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:
library Project2;

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

{$R *.res}
var
hook:cardinal; switch:boolean;

function show(ncode,wparam,lparam:integer):lresult; stdcall;
var help:lresult;
begin
help:=Callnexthookex(hook, ncode, wparam, lparam);
if wparam=107 then
case switch of
true:switch:=false;
false:switch:=true;
end;
if not switch then result:=help;
end;

function hookinstall:boolean;  stdcall;
begin
result:=false;
hook:=0;
switch:=true;
hook:=setwindowshookex(WH_Keyboard,@show,HInstance, 0);
if hook <> 0 then
result:=true;
end;

function hookuninstall:boolean;stdcall;
begin
result:=false;
unhookwindowshookex(hook);
result:=true;
end;

exports
hookinstall,
hookuninstall;
begin
end.


Dient nur einer Tastatursperre welche mit der Taste + ver-bzw. entriegelt wird.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 11.11.07 04:21 
Was macht wparam = 107???

BTW:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
case switch of
true:switch:=false;
false:switch:=true;
end;

ist für das Toggeln verantwortlich ... Jedoch prüfst Du nicht die Message, in der WParam=107 auch wirklich die gewünschte Bedeutung hat.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Wotan89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: So 11.11.07 16:29 
wparam soll für den Integerwert des Tastendruckes stehen! Das plus-zeichen steht für 107. Dieses Umschalten soll eben nur ausgelöst werden, wenn der man + drückt. Daraufhin wird dann die Tastatur gesperrt oder entsperrt. Mit der case-Anweisung müsste es doch dann immer einmal true und einmal false sein, es ist aber immer false...
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 11.11.07 16:34 
Weil der Hook für zahlreiche Nachrichten aufgerufen wird ...

Und zu einem Tastendruck gehören immer 2 Nachrichten: WM_KEYDOWN und WM_KEYUP ... Und da musst Du filtern, bei welcher er reagieren soll

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Wotan89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: So 11.11.07 19:23 
Wie kann ich denn die Messages auslesen? Außerdem stieß ich schon einmal vor das Problem den Rückgabewert zu manipulieren. Z.B. Statt der A-Taste meinetwegen die K-Taste auszugeben.... Außerdem dürfte die Funktion den Booleanwert nicht verändern, da die case-anweisung doch nur unter der Bedingung, dass wparam=107 ist, aufgerufen wird. Dies habe ich mit einer showmessage-funktion nocheinmal geprüft(case-Anweisung wird nicht ausgeführt, solange ich nicht + drücke), trotzdem hat die Variable switch den Wet false...
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 11.11.07 22:13 
RTFM. Steht in der Hilfe.

Tipp: Ist einer der Parameter ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Wotan89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mo 12.11.07 18:11 
Dankeschön :P , aber könntest du mir einen Quelltext schicken, bei dem das mit der booleanvar hinhaut? Das will bei mir nicht in den Schädel. Wäre echt nett ;).
Wotan89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mo 12.11.07 22:57 
Hat sich erledigt ;) nochmal danke
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19345
Erhaltene Danke: 1753

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 13.11.07 09:44 
user profile iconWotan89 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
case switch of
true:switch:=false;
false:switch:=true;
end;
Wie wäre es mit switch := not switch; ? ;-)