Recent

Author Topic: How can you check the state of Alt/Shift/Ctrl key in a mouse click?  (Read 5988 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1147
    • HowTos Considered Harmful?
How can you check the state of Alt/Shift/Ctrl key in a mouse click?

I think it is  doable and I have done it before, but I can't remember how.
Lazarus 3.0/FPC 3.2.2

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: How can you check the state of Alt/Shift/Ctrl key in a mouse click?
« Reply #1 on: November 15, 2012, 06:02:36 pm »
Hi,
you can:
1) Use OnMouseDown / OnMouseUp instead of OnClick.

2)This works:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var aSS: TShiftState;
begin
  aSS:=GetKeyShiftState;
  if ssCtrl in aSS then writeln('Ctrl');
  if ssAlt in aSS then ; //anything
end;

EDIT: I recognized later that using name aSS for local variable is somewhat "faux pas"  O:-) .
« Last Edit: November 15, 2012, 06:49:41 pm by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

yanes19

  • New Member
  • *
  • Posts: 36
Re: How can you check the state of Alt/Shift/Ctrl key in a mouse click?
« Reply #2 on: January 16, 2014, 02:24:16 pm »
>@Blaazen : You saved me thank you very match

 

TinyPortal © 2005-2018