Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi WM_KEYDOWN: repeat-count aus dem lparam lesen (https://www.delphipraxis.net/120720-wm_keydown-repeat-count-aus-dem-lparam-lesen.html)

Hedge 15. Sep 2008 20:15


WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Möchte gerne ermitteln ob eine Taste zum ersten Mal gedrückt wurde oder eben gehalten wird.

Das geht entweder mit WM_KEYUP, denn das wird ja nur 1 Mal ausgeführt oder auch mit dem repeat-count von WM_KEYDOWN

laut MSDN steht der repeat-count in den ersten 16 bytes des lparam.

Ich habe gelesen, dass man diese mit LOWORD (lParam) auslesen kann, aber irgendwie zündet das nicht so bei mir.

Delphi-Quellcode:
P := PEventMsg(lParam);
If P^.Message = WM_KEYDOWN then
begin
   Form1.Label1.Caption:=IntToStr((LOWORD(P^.paramL)));
end;

sirius 15. Sep 2008 20:17

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Was ist denn PeventMsg?

Hedge 15. Sep 2008 20:21

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
das Ganze ist eine Callback-Funktion:

Delphi-Quellcode:
function MouseHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
  P: PEventMsg;
begin
  Result := CallNextHookEx(0, nCode, wParam, lParam);
  If nCode = HC_ACTION then
  begin
     If lParam <> 0 then
     begin
         P := PEventMsg(lParam);
      If P^.Message = WM_KEYDOWN then
       begin
       Form1.Label1.Caption:=IntToStr((LOWORD(P^.paramL)));
       end
     end
  else
     exit;
  end;
end;

sirius 15. Sep 2008 20:26

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Und da kommt dann was raus?
IMHO wird der Zähler auch zurückgesetzt.

Hedge 15. Sep 2008 20:32

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Ich will eigentlich nur die ersten 16 Bytes des lparam isolieren, damit ich sehe wie oft die Taste aktiviert wurde hintereinander.

aus MSDN:

Zitat:

WM_KEYDOWN

WPARAM wParam
LPARAM lParam;


Parameters

wParam
Specifies the virtual-key code of the nonsystem key.
lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.

0-15
Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23
Specifies the scan code. The value depends on the OEM.
24
Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28
Reserved; do not use.
29
Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
31
Specifies the transition state. The value is always zero for a WM_KEYDOWN message.

sirius 15. Sep 2008 20:35

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Ich würde sagen: Here you are:
Zitat:

If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
Du musst also selber hochzählen. Und wann du den Zähler reseten musst, steht in Bit 30.

Hedge 15. Sep 2008 21:20

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Ah! Jetzt raff ichs. Vor dem selben Problem stand ich schon mal.

Jedoch scheint JournalHook bei den Parametern eine Schwäche zu haben, denn egal wie ich das 30. Bit prüfe, es kommt nix dabei raus...
Hier meine Testkandidaten:

Delphi-Quellcode:
const
  PREV_KEY_STATE = 1 shl 30; // $40000000
begin
  // ...
  if lparam and PREV_KEY_STATE = PREV_KEY_STATE then Beep;
  // ..
end;
und:

Delphi-Quellcode:
if Odd(lparam shr 30) then Beep;
Nix beep't

sirius 16. Sep 2008 09:12

Re: WM_KEYDOWN: repeat-count aus dem lparam lesen
 
Kein Ahnung bei dem Hook. In der normalen Message im Process funkioniert es.


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

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