HP\李良庭
2025-07-08 868daf94f29ce1ffdd799a68c07bb668cd373bcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
unit uMain;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, XpMan, Buttons, sBitBtn;
 
type
  TfrmMain = class(TForm)
    edtSelect: TEdit;
    edtText: TEdit;
    sBitBtn50: TsBitBtn;
    sBitBtn51: TsBitBtn;
    sBitBtn52: TsBitBtn;
    sBitBtn53: TsBitBtn;
    Button27: TButton;
    Button28: TButton;
    Button29: TButton;
    Button30: TButton;
    Button31: TButton;
    Button32: TButton;
    Button33: TButton;
    Button34: TButton;
    Button35: TButton;
    Button36: TButton;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    Button24: TButton;
    Button25: TButton;
    Button26: TButton;
    btnZh: TButton;
    Button37: TButton;
    procedure sBitBtn50Click(Sender: TObject);
    procedure sBitBtn51Click(Sender: TObject);
    procedure sBitBtn52Click(Sender: TObject);
    procedure sBitBtn53Click(Sender: TObject);
    procedure btnZhClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    glInkOutput : String;
    procedure InsertStringAtCursor(EditControl: TEdit; Str: string);
    procedure DeleteCharsBeforeCursor(EditControl: TEdit; Count: Integer=1);
  end;
 
var
  frmMain: TfrmMain;
 
implementation
 
{$R *.dfm}
 
//------------------------------------------------------------------------------
// Ä£ÄⰴϺÍÊͷŰ´¼ü
procedure SimulateKeyPress(KeyCode: Word);
begin
  keybd_event(KeyCode, MapVirtualKey(KeyCode, 0), 0, 0);
  keybd_event(KeyCode, MapVirtualKey(KeyCode, 0), KEYEVENTF_KEYUP, 0);
end;
 
// Ä£ÄⰴϺÍÊÍ·Å×éºÏ¼ü
procedure SimulateCombinationKeyPress(KeyCode1, KeyCode2: Word);
begin
  keybd_event(KeyCode1, MapVirtualKey(KeyCode1, 0), 0, 0);
  keybd_event(KeyCode2, MapVirtualKey(KeyCode2, 0), 0, 0);
  keybd_event(KeyCode2, MapVirtualKey(KeyCode2, 0), KEYEVENTF_KEYUP, 0);
  keybd_event(KeyCode1, MapVirtualKey(KeyCode1, 0), KEYEVENTF_KEYUP, 0);
end;
 
//------------------------------------------------------------------------------
//´Ó¹â±ê´¦²åÈë×Ö·û
procedure TfrmMain.InsertStringAtCursor(EditControl: TEdit; Str: string);
begin
  // ±£´æµ±Ç°¹â±êλÖÃ
  EditControl.SelStart := EditControl.SelStart;
  EditControl.SelLength := 0; // ²»Ñ¡ÔñÈκÎÎı¾£¬È·±£Ö»²åÈë¶ø²»Ìæ»»
  EditControl.SelText := Str; // ²åÈë×Ö·û´®
end;
 
//×Ô¶¨Ò庯Êý£º´Ó¹â±ê´¦É¾³ý×Ö·û
procedure TfrmMain.DeleteCharsBeforeCursor(EditControl: TEdit; Count: Integer=1);
var
  CursorPos, NewStart: Integer;
begin
  CursorPos := EditControl.SelStart;
  if CursorPos >= Count then
  begin
    NewStart := CursorPos - Count; // ¼ÆËãеÄÑ¡ÔñÆðµã
    EditControl.SelStart := NewStart;
    EditControl.SelLength := Count; // Ñ¡ÔñCount¸ö×Ö·û
    EditControl.SelText := '';      // É¾³ýÑ¡¶¨µÄÎı¾
  end
  else
  begin
    // Èç¹ûCount´óÓÚ¹â±êλÖã¬Ôòɾ³ýËùÓÐÔÚ¹â±ê֮ǰµÄ×Ö·û
    EditControl.SelStart := 0;
    EditControl.SelLength := CursorPos;
    EditControl.SelText := '';
  end;
end;
 
//------------------------------------------------------------------------------
//Çå³ýËùÓÐÊäÈë
procedure TfrmMain.sBitBtn50Click(Sender: TObject);
begin
  edtSelect.Clear;
end;
 
//È·ÈÏ×Ö·û
procedure TfrmMain.sBitBtn51Click(Sender: TObject);
begin
  //°Ñ´ýѡȡÎÄ×Ö¿½±´µ½edtTextÖÐ
  InsertStringAtCursor(edtText, Trim(edtSelect.Text));
end;
 
//ɾ³ý×Ö·û
procedure TfrmMain.sBitBtn52Click(Sender: TObject);
begin
  DeleteCharsBeforeCursor(edtText);
end;
 
//¿½±´ÊäÈëÄÚÈÝ£¬Í˳ö
procedure TfrmMain.sBitBtn53Click(Sender: TObject);
begin
  //½«½á¹û¸üе½È«¾Ö±äÁ¿
  glInkOutput := edtText.Text;
  Close();
end;
 
// Çл»µ½ÖÐÎÄÊäÈë·¨
procedure TfrmMain.btnZhClick(Sender: TObject);
begin
  // ¼ÙÉèʹÓàCtrl + ¿Õ¸ñÇл»ÊäÈë·¨
  SimulateCombinationKeyPress(VK_CONTROL, VK_SPACE);
end;
 
//------------------------------------------------------------------------------
// ×Ö·û°´Å¥´¦Àí³ÌÐò
procedure TfrmMain.Button1Click(Sender: TObject);
var
  KeyChar: Char;
  KeyCode: Word;
begin
  //ÆÁÄ»¼üÅÌÊäÈë×Öĸ
  if TButton(Sender).Tag<=37 then begin
    KeyChar := TButton(Sender).Caption[1]; // ÌáÈ¡°´Å¥ Caption ×Ö·û
    KeyCode := VkKeyScan(KeyChar);
    SimulateKeyPress(KeyCode);
  end;
  edtSelect.SetFocus;
end;
 
end.