BSOne.SFC/Tocsg.Module/SunkAssister/EXE_SunkAssister/View/DKeyInput.pas

96 lines
2.2 KiB
Plaintext

unit DKeyInput;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Menus;
type
TDlgKeyInput = class(TForm)
mmKeyInput: TMemo;
Splitter1: TSplitter;
mmKeylog: TMemo;
popFun: TPopupMenu;
miClear: TMenuItem;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure miClearClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
procedure ProcessKeyInput(nInput: NativeInt; aShiftState: TShiftState);
end;
var
gKeyInput: TDlgKeyInput = nil;
DlgKeyInput: TDlgKeyInput;
implementation
uses
Tocsg.Process, Tocsg.Keyboard;
{$R *.dfm}
Constructor TDlgKeyInput.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
ASSERT(gKeyInput = nil);
gKeyInput := Self;
end;
Destructor TDlgKeyInput.Destroy;
begin
gKeyInput := nil;
Inherited;
end;
procedure TDlgKeyInput.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TDlgKeyInput.miClearClick(Sender: TObject);
begin
mmKeyInput.Clear;
mmKeylog.Clear;
end;
procedure TDlgKeyInput.ProcessKeyInput(nInput: NativeInt; aShiftState: TShiftState);
var
sKey: String;
hActiveWnd: HWND;
dwPID: DWORD;
begin
sKey := '';
if ssShift in aShiftState then
sKey := '[Shift] ';
if ssCtrl in aShiftState then
sKey := sKey + '[Ctrl] ';
if ssAlt in aShiftState then
sKey := sKey + '[Alt] ';
dwPID := 0;
hActiveWnd := GetForegroundWindow;
if hActiveWnd <> 0 then
dwPID := GetProcessPIDFromWndHandle(hActiveWnd);
if dwPID <> 0 then
mmKeyInput.Lines.Add(Format('[%s(%d)] %s %s - KeyCode = %d', [GetProcessNameByPid(dwPID), dwPID, sKey, Char(nInput), nInput]))
else
mmKeyInput.Lines.Add(Format('[Unknown process] %s %s - KeyCode = %d', [sKey, Char(nInput), nInput]));
if nInput = 13 then
mmKeylog.Text := mmKeylog.Text + GetInputKeyToStr(nInput) + #13#10
else
mmKeylog.Text := mmKeylog.Text + GetInputKeyToStr(nInput);
end;
end.