Add hotkey interface
This commit is contained in:
parent
0e0cb7e0e2
commit
5fc5095224
|
@ -62,6 +62,15 @@
|
|||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="Pair"/>
|
||||
</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>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
@ -72,7 +81,7 @@
|
|||
</Target>
|
||||
<SearchPaths>
|
||||
<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)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
|
|
|
@ -10,8 +10,7 @@ uses
|
|||
athreads,
|
||||
{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, TMainForm, App, Config, ConfigVO, pair
|
||||
{ you can add units after this };
|
||||
Forms, TMainForm, App, Config, ConfigVO, pair, Hotkey, win.hotkey;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
|
|
@ -11,4 +11,3 @@ uses
|
|||
implementation
|
||||
|
||||
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
|
||||
ClientWidth = 500
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '4.0.0.4'
|
||||
OnKeyPress = MainEditKeyPress
|
||||
OnShortCut = FormShortCut
|
||||
object MainEdit: TEdit
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Side = asrCenter
|
||||
AnchorSideBottom.Side = asrCenter
|
||||
Left = 10
|
||||
Height = 48
|
||||
Top = 0
|
||||
Height = 40
|
||||
Top = 5
|
||||
Width = 480
|
||||
AutoSize = False
|
||||
BorderSpacing.CellAlignHorizontal = ccaCenter
|
||||
|
@ -25,6 +28,7 @@ object MainUI: TMainUI
|
|||
ParentFont = False
|
||||
TabOrder = 0
|
||||
TextHint = 'Hi, Power tools'
|
||||
OnKeyPress = MainEditKeyPress
|
||||
end
|
||||
object MainTrayIcon: TTrayIcon
|
||||
BalloonFlags = bfInfo
|
||||
|
|
|
@ -5,9 +5,21 @@ unit TMainForm;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
|
||||
Menus;
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, LCLType,
|
||||
Menus, LMessages;
|
||||
{*
|
||||
Code Architecture
|
||||
|
||||
[View] - [Model]
|
||||
|
|
||||
[Controller]
|
||||
/ \
|
||||
[Components] [Util]
|
||||
|
|
||||
[Platform]
|
||||
/ | \
|
||||
[Windpws] [Linux] [MacOS]
|
||||
*}
|
||||
type
|
||||
|
||||
{ TMainUI }
|
||||
|
@ -20,7 +32,10 @@ type
|
|||
SettingsMenu: TMenuItem;
|
||||
ShowOrHideMenu: TMenuItem;
|
||||
TrayPopupMenu: TPopupMenu;
|
||||
procedure FormShortCut(var Msg: TLMKey; var Handled: boolean);
|
||||
procedure ShowOrHideMainUI();
|
||||
procedure ExitMenuClick(Sender: TObject);
|
||||
procedure MainEditKeyPress(Sender: TObject; var Key: char);
|
||||
procedure ShowOrHideMenuClick(Sender: TObject);
|
||||
private
|
||||
|
||||
|
@ -37,15 +52,42 @@ implementation
|
|||
|
||||
{ TMainUI }
|
||||
|
||||
procedure TMainUI.ShowOrHideMenuClick(Sender: TObject);
|
||||
procedure TMainUI.ShowOrHideMainUI();
|
||||
begin
|
||||
MainUI.Visible := not MainUI.Visible;
|
||||
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);
|
||||
begin
|
||||
MainUI.Close();
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue