Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: TrackBar und GetAsyncKeyState hat Probleme mit der linken Maustaste in RADstudio1

  Alt 4. Okt 2022, 12:33
Ich habe zwar keine Ahnung warum Du überhaupt "GetAsyncKeyState" in Vcl mit einbaust aber VK_LButton muss nicht unbedingt VK_LButton sein.
Zitat:
Remarks
The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling GetSystemMetrics(SM_SWAPBUTTON).

which returns TRUE if the mouse buttons have been swapped.

Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the preemptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.

You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right.
Delphi-Quellcode:
function IsMouseButtonPressed(AButton, ASwapButton: Integer): Boolean;
begin
  if GetSystemMetrics(SM_SWAPBUTTON) = 0 then
    Result := GetAsyncKeyState(AButton) < 0
  else
    Result := GetAsyncKeyState(ASwapButton) < 0;
end;

function LeftButtonPressed: Boolean;
begin
  Result := IsMouseButtonPressed(VK_LBUTTON, VK_RBUTTON);
end;

function RightButtonPressed: Boolean;
begin
  Result := IsMouseButtonPressed(VK_RBUTTON, VK_LBUTTON);
end;
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat