?
Solved

Hotkey component for form onkeydown event?

Posted on 2001-08-30
7
Medium Priority
?
416 Views
Last Modified: 2010-04-06
Is it possible for a hotkey component to be used to configure the key combinations pressed in a form's onkeydown event?

I would like to create two forms where the first form has the hotkey event that configures the hotkey combination. When the second window is displayed, a hidden component is visible when the user presses the combination keys on the form that's configured in the first form.

I would appreciate source code implemented in the answers, thanks.
0
Comment
Question by:NitroBlaze
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 6443665
Hi NitroBlaze,

I am not sure I understand completely what you mean.

Just let me know if this is it.

Is it something like this:

  class TForm1(TForm)
    procedure FormCreate(Sender: TObject);
    HotKeyController: THotKeyController; (* your component *)
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  HotKeyController.Key := VK_ENTER;
  HotKeyController.Shift := [ssCtrl, ssAlt];
end;

  class TForm2(TForm)
    Form2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  end;


procedure Form2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Form1.HotKeyController.Test(Key, Shift) then
  begin
    MyHiddenControl.Visible := True;
  end;
end;

Regards Jacco
0
 

Author Comment

by:NitroBlaze
ID: 6447203
is it possible to use the pre-installed Hotkey component located in the Advanced components tab in Delphi? It handles different properties like Modifiers for the Shift and Shortcut for the Key property.
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6447208
Delphi 6 right? I don't have it at home.

Regards Jacco
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:NitroBlaze
ID: 6447219
Yes. In that case, what components do you recommend me to check out on this matter? Thanks.
0
 
LVL 10

Accepted Solution

by:
Jacco earned 300 total points
ID: 6450622
Hi NitroBlaze,

In the office I have Delphi six so I've tried to make you a sample. Here is a sample on how to do it.

Good luck and regards Jacco

*** start of code ***
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    HotKey1: THotKey;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TForm2.Create(Self) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

end.
*** end of code ***
*** start of code ***
unit Unit2;

interface

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

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

var
  Form2: TForm2;

implementation

uses
  Unit1, QMenus;

{$R *.dfm}

procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if ShortCut(Key, Shift) = Form1.HotKey1.HotKey then
    Memo1.Visible := True;
end;

end.
*** end of code ***
0
 

Author Comment

by:NitroBlaze
ID: 6451930
The code does not accept common windows keyboard shortcuts like (Ctrl-A : Select All), that's workable by registering the combination beforehand, other than that, it works perfectly.

Thanks.
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6452287
Try setting KeyPreview of the form to True

If you do that the form will see the key first. If you set Key to 0 in FormKeyDown the active control of the form will not handle the key. (It is tricky sometimes though).

And don't forget the HotKey component has a property for not allowing some key combinations.

Regards Jacco

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question