Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shift [ and shift ] 2

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I am trying to capture the shift [ and shift ] in the formkeydown event to modify a trackbar.
I think i am supposed to use the GetAsyncKeyState command but cannot figure out on how to make it work when you press the Shift [ combinations keys.
would someone know?
Thanks.
Pierrotsc
 
Nope.went there already. It does not tell me on how to find out if Shift [ is pressed. I can do [ but cannot figure out on how to check for shift [.
Thanks...
 
Code:
 if (key =219) and (Shift = [ssShift]) then showmessage('pressed');
 
???

Code:
if (Shift = [ssShift]) and (Key = YOUR_KEYCODE) then
 DoIt;

or am I missing something?


-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
damn too late :)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thanks guys..It is kind of working because if i press the [ by itself, it also triggers like the shift [.Right now I use if (getasynckeystate($DB)=1 and 1)=1 then... to check the status of [.
if i use if (key =219) and (Shift = [ssShift]) then

This command triggers both [ and shift [...
What should I do?

P
 
Respectfully, you must have done something wrong. I can press [ and it doesn't show my message.

Make sure you don't also have code in OnKeyUp or OnKeyPress.
 
I have the code in formkeydown. Should i not be using that?
 
Cannot use onkeyfress if you use shift=. It has to be onkeydown..
 
Here's my .pas code:
Code:
unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm5 = class(TForm)
    Edit1: TEdit;
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
    if (key =219) and (Shift = [ssShift]) then showmessage('done');
end;

end.
 
Ok..Try that.
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key =219) and (Shift = [ssShift]) then showmessage('Shift [');
if (key =219) then showmessage('[');
end;

end.

When you press shift [, both message will appear...
 
Tried.

Now then...if you're asking if you can trap only Shift+[ or [ and not both at the same time then do this:
Code:
    if (key =219) and (Shift = [ssShift]) then showmessage('Shift [');
    if (key =219) and (Shift <> [ssShift]) then showmessage('[');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top