Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   TrackBar und GetAsyncKeyState hat Probleme mit der linken Maustaste in RADstudio11 (https://www.delphipraxis.net/211558-trackbar-und-getasynckeystate-hat-probleme-mit-der-linken-maustaste-radstudio11.html)

thomaskroger 4. Okt 2022 10:50

TrackBar und GetAsyncKeyState hat Probleme mit der linken Maustaste in RADstudio11
 
Was gestern ging muss heute nicht zwingend gehen...

Bislang verwendete ich folgenden Code um beim Loslassen der linken Maustaste die aktuelle Position der Trackbar auszuwerten.
In RAD Studio 11, also Delphi und C++, geht es nicht mehr:

Delphi-Quellcode:
void __fastcall TForm9::TrackBar1Change(TObject *Sender)
{
   int AsyncKeyState_VK_LBUTTON = GetAsyncKeyState(VK_LBUTTON);    //VK_LBUTTON $1 Linke Maustaste
   Memo1->Lines->Add(IntToHex(AsyncKeyState_VK_LBUTTON, 4));

//   if (GetAsyncKeyState(VK_LBUTTON) == 0)
   if (AsyncKeyState_VK_LBUTTON ==0)
   {
      Memo1->Lines->Add(IntToHex(AsyncKeyState_VK_LBUTTON,4));
   }
}
Dabei wurde bei gedrückter Maustaste FFFF8000 zurück gegeben und nach einem Tasten-Release eine 0.
Nun wird aber nach dem Update von RADstudio 10 auf 11 nach einem Tasten-Release kein TrackBar1Change-Ereignis mehr ausgelöst.. ?
In älteren C++ Kompilationen (RADstudio10, Delphi XE6) geht es einwandfrei.

Delphi-Quellcode:
procedure TForm9.TrackBar1Change(Sender: TObject);
var
 i:integer;
begin
    i:= GetAsyncKeyState(VK_LBUTTON);
    Memo1.Lines.Add(IntToHex(i, 4));

  if (i =0) then
  begin
   Memo1.Lines.Add(IntToHex(i, 4));
  end;
end;
Delphi XE6 , wobei allerdings zwei mal TrackBar1Change ausgelöst wird:
(4 mal 0 wegen 2 mal Memo1.Lines.Ad)

FFFF8001 Bewegen
0000 loslassen
0000
0000
0000

Also, mit Delphi XE6 und RADstudio10 geht es wie bisher einwandfrei, in RADstudio11 nicht:
Die Frage ist, was hat sich verändert?
Gibt es Parameter, an denen wir drehen können?
Workaround?

Vielen Dank für frischen Ideen :)

thomaskroger 4. Okt 2022 12:14

gelöst:TrackBar und GetAsyncKeyState hat Probleme mit der linken Maustaste
 
gelöst:

On Tracking verwenden:

Delphi-Quellcode:
procedure TForm9.TrackBar1Tracking(Sender: TObject);

KodeZwerg 4. Okt 2022 12:33

AW: TrackBar und GetAsyncKeyState hat Probleme mit der linken Maustaste in RADstudio1
 
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;

himitsu 4. Okt 2022 12:38

AW: TrackBar und GetAsyncKeyState hat Probleme mit der linken Maustaste in RADstudio1
 
Wobei hier wohl GetKeyState besser wäre, als ein GetAsyncKeyState.

GetKeyState gibt den Zustand zum Zeitpunktes des Events zurück und nicht, wenn das Programm 'nen bissl hängt, den vom aktuellen Zeitpunkt (wie GetAsyncKeyState)


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:59 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 by Thomas Breitkreuz