Manipulators

Detect tab-key pressing

Posted in Manipulators

Use CM_DIALOGKEY message. Create special procedure to hook this message and make something, when result is Tab key.

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure CMDialogKey(var Msg: TCMDialogKey);
      message CM_DIALOGKEY;
  public
    { Public declarations }
  end;

...

procedure TForm1.CMDialogKey(var msg: TCMDialogKey);
begin
  if Msg.CharCode=VK_TAB then
    Caption:='Tab Key was pressed';
end;

Detect rigth/left shift key

Posted in Manipulators

Use GetKeyNameText function. For example:

type
  TForm1 = class(TForm)
    Label1: TLabel;
  private
    procedure MyMessage(var Msg: TWMKeyDown); message WM_KEYDOWN;
    { Private declarations }
  public
    { Public declarations }
  end;
...
procedure TForm1.MyMessage(var Msg: TWMKeyDown);
var
  P: PCHar;
begin
  P:=StrAlloc(150);
  if Msg.CharCode=16 then
    GetKeyNameText(Msg.KeyData, P, 150)
  else StrPCopy(P, 'Other Key');
  Label1.Caption:=StrPas(P);
end;
 

Detect insert-key

Posted in Manipulators

Use GetKeyStatus function with VK_INSERT parameter.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if GetKeyState(VK_INSERT)=0 then
    Label1.Caption:='Insert'
  else Label1.Caption:='Replace';
end;

Detect arrow keys

Posted in Manipulators

Use the KeyDown or KeyUp events, and test VK_LEFT, VK_RIGHT keys and etc.

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of
    VK_LEFT: Label2.Caption:='This is a LEFT';
    VK_RIGHT: Label2.Caption:='This is a RIGHT';
    VK_UP: Label2.Caption:='This is a UP';
    VK_DOWN: Label2.Caption:='This is a DOWN';
  end;
end;

Detect a wheel of mouse

Posted in Manipulators

Use GetSystemMetrics function with SM_MOUSEWHEELPRESENT parameter. Note: for Windows NT only.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if GetSystemMetrics(SM_MOUSEWHEELPRESENT)<>0 then
    Label1.Caption:='You have a wheel'
  else
    Label1.Caption:='You have not a wheel';
end;