Add hotkey interface
This commit is contained in:
parent
0e0cb7e0e2
commit
5fc5095224
|
@ -62,6 +62,15 @@
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="Pair"/>
|
<UnitName Value="Pair"/>
|
||||||
</Unit>
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="src\components\hotkey\hotkey.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="Hotkey"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="src\os\win\win.hotkey.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -72,7 +81,7 @@
|
||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
<OtherUnitFiles Value="src\view;src\os\win;src\components\config;src\model"/>
|
<OtherUnitFiles Value="src\view;src\os\win;src\components\config;src\model;src\components\hotkey"/>
|
||||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Linking>
|
<Linking>
|
||||||
|
|
|
@ -10,8 +10,7 @@ uses
|
||||||
athreads,
|
athreads,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Interfaces, // this includes the LCL widgetset
|
Interfaces, // this includes the LCL widgetset
|
||||||
Forms, TMainForm, App, Config, ConfigVO, pair
|
Forms, TMainForm, App, Config, ConfigVO, pair, Hotkey, win.hotkey;
|
||||||
{ you can add units after this };
|
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,3 @@ uses
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
unit Hotkey;
|
||||||
|
|
||||||
|
{$mode ObjFPC}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils;
|
||||||
|
|
||||||
|
type
|
||||||
|
IHotkey = interface
|
||||||
|
function ListHotkeys(): string; virtual;
|
||||||
|
function SetHotkey(Hotkey: string): boolean; virtual;
|
||||||
|
function RegisterHotkey(Hotkey: string): boolean; virtual;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
end.
|
|
@ -0,0 +1,42 @@
|
||||||
|
unit win.hotkey;
|
||||||
|
|
||||||
|
{$mode ObjFPC}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, Hotkey;
|
||||||
|
|
||||||
|
{* Hotkey implement on Windows *}
|
||||||
|
|
||||||
|
type
|
||||||
|
WinHotkey = class(TInterfacedObject, IHotkey)
|
||||||
|
private
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
public
|
||||||
|
function ListHotkeys(): string;
|
||||||
|
function SetHotkey(Hotkey: string): boolean;
|
||||||
|
function RegisterHotkey(Hotkey: string): boolean;
|
||||||
|
published
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
function WinHotkey.ListHotkeys(): string;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function WinHotkey.SetHotkey(Hotkey: string): boolean;
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function WinHotkey.RegisterHotkey(Hotkey: String): boolean;
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
|
@ -7,14 +7,17 @@ object MainUI: TMainUI
|
||||||
ClientHeight = 50
|
ClientHeight = 50
|
||||||
ClientWidth = 500
|
ClientWidth = 500
|
||||||
Position = poScreenCenter
|
Position = poScreenCenter
|
||||||
|
LCLVersion = '4.0.0.4'
|
||||||
|
OnKeyPress = MainEditKeyPress
|
||||||
|
OnShortCut = FormShortCut
|
||||||
object MainEdit: TEdit
|
object MainEdit: TEdit
|
||||||
AnchorSideLeft.Side = asrCenter
|
AnchorSideLeft.Side = asrCenter
|
||||||
AnchorSideTop.Side = asrCenter
|
AnchorSideTop.Side = asrCenter
|
||||||
AnchorSideRight.Side = asrCenter
|
AnchorSideRight.Side = asrCenter
|
||||||
AnchorSideBottom.Side = asrCenter
|
AnchorSideBottom.Side = asrCenter
|
||||||
Left = 10
|
Left = 10
|
||||||
Height = 48
|
Height = 40
|
||||||
Top = 0
|
Top = 5
|
||||||
Width = 480
|
Width = 480
|
||||||
AutoSize = False
|
AutoSize = False
|
||||||
BorderSpacing.CellAlignHorizontal = ccaCenter
|
BorderSpacing.CellAlignHorizontal = ccaCenter
|
||||||
|
@ -25,6 +28,7 @@ object MainUI: TMainUI
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
TextHint = 'Hi, Power tools'
|
TextHint = 'Hi, Power tools'
|
||||||
|
OnKeyPress = MainEditKeyPress
|
||||||
end
|
end
|
||||||
object MainTrayIcon: TTrayIcon
|
object MainTrayIcon: TTrayIcon
|
||||||
BalloonFlags = bfInfo
|
BalloonFlags = bfInfo
|
||||||
|
|
|
@ -5,9 +5,21 @@ unit TMainForm;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, LCLType,
|
||||||
Menus;
|
Menus, LMessages;
|
||||||
|
{*
|
||||||
|
Code Architecture
|
||||||
|
|
||||||
|
[View] - [Model]
|
||||||
|
|
|
||||||
|
[Controller]
|
||||||
|
/ \
|
||||||
|
[Components] [Util]
|
||||||
|
|
|
||||||
|
[Platform]
|
||||||
|
/ | \
|
||||||
|
[Windpws] [Linux] [MacOS]
|
||||||
|
*}
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TMainUI }
|
{ TMainUI }
|
||||||
|
@ -20,7 +32,10 @@ type
|
||||||
SettingsMenu: TMenuItem;
|
SettingsMenu: TMenuItem;
|
||||||
ShowOrHideMenu: TMenuItem;
|
ShowOrHideMenu: TMenuItem;
|
||||||
TrayPopupMenu: TPopupMenu;
|
TrayPopupMenu: TPopupMenu;
|
||||||
|
procedure FormShortCut(var Msg: TLMKey; var Handled: boolean);
|
||||||
|
procedure ShowOrHideMainUI();
|
||||||
procedure ExitMenuClick(Sender: TObject);
|
procedure ExitMenuClick(Sender: TObject);
|
||||||
|
procedure MainEditKeyPress(Sender: TObject; var Key: char);
|
||||||
procedure ShowOrHideMenuClick(Sender: TObject);
|
procedure ShowOrHideMenuClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -37,15 +52,42 @@ implementation
|
||||||
|
|
||||||
{ TMainUI }
|
{ TMainUI }
|
||||||
|
|
||||||
procedure TMainUI.ShowOrHideMenuClick(Sender: TObject);
|
procedure TMainUI.ShowOrHideMainUI();
|
||||||
begin
|
begin
|
||||||
MainUI.Visible := not MainUI.Visible;
|
MainUI.Visible := not MainUI.Visible;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainUI.FormShortCut(var Msg: TLMKey; var Handled: boolean);
|
||||||
|
begin
|
||||||
|
// MainEdit.Text := Chr(Msg.CharCode);
|
||||||
|
case Msg.CharCode of
|
||||||
|
VK_CONTROL, VK_L:
|
||||||
|
begin
|
||||||
|
MainUI.ShowOrHideMainUI();
|
||||||
|
Handled := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainUI.ShowOrHideMenuClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
MainUI.ShowOrHideMainUI();
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainUI.ExitMenuClick(Sender: TObject);
|
procedure TMainUI.ExitMenuClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
MainUI.Close();
|
MainUI.Close();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainUI.MainEditKeyPress(Sender: TObject; var Key: char);
|
||||||
|
begin
|
||||||
|
if Key = Chr(VK_ESCAPE) then
|
||||||
|
begin
|
||||||
|
// ShowOrHideMainUI();
|
||||||
|
end;
|
||||||
|
|
||||||
|
// MainUI.MainEdit.Text := 'Key ' + Key + ' Pressed';
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue