• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Trapping Windows button

I am not sure if this is an easy task but:

how can i  trap the Windows button??

Regards
Keith
0
keithcsl
Asked:
keithcsl
  • 5
  • 2
1 Solution
 
d003303Commented:
Hum, Windows button ? Do you mean the minimize/maximize buttons on the title bar ?
0
 
ZifNabCommented:
You mean the new windows button on the keyboard (win95 ,NT)?
0
 
ZifNabCommented:
I believe, you have to check for the VK_LWin or VK_RWin key.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
ZifNabCommented:
This should it be, if I correctly understood the question :

Use Plain form, copy this source to the unit, run it and push left or right window button on keyboard.

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  var i : integer;
begin
 If Key = VK_LWIn then showmessage('left');
 if key = vk_RWin then showmessage('right');
end;

end.

Regards,
ZifNab;
0
 
keithcslAuthor Commented:
I am so soree but I meant the Windows key on the keyboard. Should have made my question more clearly..

Keith
0
 
ZifNabCommented:
Keithcsl, the source code I gave you is meant for the windows key on the keyboard!!! The left and the right one!
0
 
keithcslAuthor Commented:
ZifNab

Oh my, I am sorry for not reading your answer properly. The code works fine. Thanx!

If it is not too much to ask, is there a way to cancel the Keydown event?, ie i don't want the user to be able to press the Windows Key.

Thanx
Keith
0
 
ZifNabCommented:
Hi Keith,
I don't know really, it seems that the key is directely sended to windows. You can't just assign another value to Key as normally. I'll try to find a solution, but I can't promise anything.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now