How to manually get TMouseButton in C++Builder

How to manually get TMouseButton in C++Builder



I am using C++Builder from Embarcadero Technology. The built in OnClick event handler does not identify if the mouse click is the left or right button. Is there a function I can call to manually fill the values for TMouseButton. Below is the OnClick event handler?


void __fastcall TForm::ListBox1Click(TObject *Sender)

TMouseButton Button;

Button = ???






use evens that has TShiftState Shift (OnMouseUp/Down/Move) and remember the Shift into your variable Form1->sh . Then if you need just use if (Form1->sh.Contains(ssLeft)) ... the buttons are ssLeft,ssRight,ssMiddle also some keys are handy ssShift,ssAlt,ssCtrl I usually also remember x,y position from OnMouseMove as I tend to use it a lot for stuff like selection focus switching/freeing etc. see drag & drop C++/VCL example

– Spektre
Sep 10 '18 at 7:04



TShiftState Shift


Shift


Form1->sh


if (Form1->sh.Contains(ssLeft)) ...


ssLeft,ssRight,ssMiddle


ssShift,ssAlt,ssCtrl


x,y


OnMouseMove




2 Answers
2



As others have mentioned, you can use the OnMouseDown event to remember the current mouse button state for use in OnClick, eg.


OnMouseDown


OnClick


private:
bool LButtonDown;
bool RButtonDown;

...

void __fastcall TForm1::ListBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

switch (Button)
case mbLeft:
LButtonDown = true;
break;

case mbRight:
RButtonDown = true;
break;



void __fastcall TForm1::ListBox1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

switch (Button)
case mbLeft:
LButtonDown = false;
break;

case mbRight:
RButtonDown = false;
break;



void __fastcall TForm::ListBox1Click(TObject *Sender)

if (LButtonDown) ...
if (RButtonDown) ...



If you don't want to do that way, you can use the Win32 API GetKeyState() or GetAsyncKeyState() function to query the current state of the mouse's left and right buttons, using the VK_LBUTTON and VK_RBUTTON virtual key codes, eg:


GetKeyState()


GetAsyncKeyState()


VK_LBUTTON


VK_RBUTTON


void __fastcall TForm::ListBox1Click(TObject *Sender)

if (GetKeyState(VK_LBUTTON)) ...
if (GetKeyState(VK_RBUTTON)) ...



The correct event to use for details of mouse click events is OnMouseDown (also OnMouseUp and OnMouseMove).


OnMouseDown


OnMouseUp


OnMouseMove



Override the event and then implement MouseDown event like this


void __fastcall TMyListView::MouseDown(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y)

if (Button == mbLeft)


if (Button == mbRight)





See also Vcl.Controls.TControl.OnMouseDown in Embarcadero's documentation.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages