Solved

Hotkey component for form onkeydown event?

Posted on 2001-08-30
7
383 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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 100 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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