-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremote.pas
746 lines (649 loc) · 30.6 KB
/
remote.pas
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
{ remote control module }
unit Remote;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, ExtCtrls, ThdTimer;
const
RXBUFSIZE = 1024; { TCP buffer size per received chunk }
CMDQUEUESIZE = 2048; { max # of queued key entry commands }
MAXCMDLEN = 25; { maximum length of command name }
MAXPARAMS = 8; { max # of parameters for a command }
MAXPARAMLEN = 16; { maximum length of a parameter string }
MAXCONNECTIONS = 8; { maximum number of concurrent TCP connections }
type
TCmdParserState = ( sAny, sToken, sParams, sEsc, sCsi ); { parser states }
TCmdType = ( cNone, cKey, cRequest, cCommand ); { remote command types }
TRequestType = ( RPOWER, RPAUSE, RGETMEM, RVMEM, RSLEEP, RVERSION, RMAX ); { request types (ask for something) }
TCommandType = ( CPOWER, CPAUSE, CSAVEMEM, CLOADMEM, CRESET, CWAKEUP, CMAX ); { command types (do something) }
{ command descriptor }
TCmd = record
parserState: TCmdParserState;
ctype: TCmdType;
keycode: integer;
ch: char;
paramcount: integer;
connId: integer;
name: String[MAXCMDLEN];
params: array [0..MAXPARAMS-1] of String[MAXPARAMLEN];
end;
TRemoteForm = class(TForm)
RcSocket: TServerSocket;
RcConnectedPanel: TPanel;
RcActiveLed: TPanel;
LedTimer: TTimer;
KeyUpTimer: TThreadedTimer;
QueueTimer: TThreadedTimer;
procedure FormCreate(Sender: TObject);
procedure RcSocketClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure RcSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure RcSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure RcSocketClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure LedTimerTimer(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure KeyUpTimerTimer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure QueueTimerTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
CmdCache: Array [0..MAXCONNECTIONS] of TCmd; { MAXCONNECTIONS + last one for string macros }
KeyNameStrings: TStringList;
RequestNameStrings: TStringList;
CommandNameStrings: TStringList;
{ Command queue }
CmdQueue: Array[0..CMDQUEUESIZE-1] of TCmd;
CmdQueueWrite: Integer; { head }
CmdQueueRead: Integer; { tail }
CmdQueued: Integer; { depth }
procedure EnqueueCmd( var cmd: TCmd);
procedure DequeueCmd;
procedure ExecCmd(var c: TCmd);
procedure ParseBuf(var buf: array of byte; len: integer; var cmd: TCmd);
procedure SendResponse(connId: integer; var buf; len: integer);
procedure DispatchKeyCode(kc:integer);
public
procedure ParseString(s: string);
{ Public declarations }
end;
{ just a shim to access .Address of a TServerSocket }
TBindingSocket = Class(TServerSocket);
var
RemoteForm: TRemoteForm;
gotClosed: boolean;
implementation
uses Main, Def, Cpu, Keyboard, Lcd, Serial;
{$R *.DFM}
const
KEYNCOUNT = 27;
{ list of key command tokens }
KeyNameList: array [0..KEYNCOUNT-1] of String = (
'TAB', 'MEMO', 'IN', 'OUT', 'CALC', 'S',
'CAPS', 'SPC', 'ANS',
'INS', 'UP', 'DEL', 'MENU',
'LEFT', 'DOWN', 'RIGHT', 'CAL',
'BRK', 'CLS', 'BS', 'EXE',
'M1', 'M2', 'M3', 'M4', 'ETC',
'NEWALLYESIMSURE'
// also: 'WAKEUP', 'NEWALL', 'RESET' are also handled as keys
);
{ list of corresponding VK_ key codes }
KeyList: array [0..KEYNCOUNT-1] of Integer = (
KC_TAB, KC_MEMO, KC_IN, KC_OUT, KC_CALC, KC_SHIFT,
KC_CAPS, KC_SPC, KC_ANS,
KC_INS, KC_UP, KC_DEL, KC_MENU,
KC_LEFT, KC_DOWN, KC_RIGHT, KC_CAL,
KC_BRK, KC_CLS, KC_BS, KC_EXE,
KC_M1, KC_M2, KC_M3, KC_M4, KC_ETC,
KC_NEWALL
);
{ list of request names - this MUST match the order of the TRequestType enum }
RequestNameList: array [0..Integer(RMAX)-1] of String = (
'POWER', 'PAUSE', 'GETMEM', 'VMEM', 'SLEEP', 'VERSION'
);
{ list of request names - this MUST match the order of the TRequestType enum }
CommandNameList: array [0..Integer(CMAX)-1] of String = (
'POWER', 'PAUSE', 'SAVEMEM', 'LOADMEM', 'RESET', 'WAKEUP'
);
procedure TRemoteForm.FormCreate(Sender: TObject);
var i: integer;
begin
gotClosed := false;
CmdQueued := 0;
CmdQueueRead := 0;
CmdQueueWrite := 0;
fillchar(cmdCache, Length(cmdCache)* sizeof(TCmd), 0);
{ key entry interval }
QueueTimer.Interval := MainForm.KeyInterval;
KeyUpTimer.Interval := round(MainForm.KeyInterval / 4);
{ populate KeyNameStrings with a list of names }
KeyNameStrings := TStringList.Create;
for i := 0 to KEYNCOUNT - 1 do KeyNameStrings.Add(KeyNameList[i]);
{ populate RequestNameStrings with a list of names }
RequestNameStrings := TStringList.Create;
for i := 0 to Integer(RMAX) - 1 do RequestNameStrings.Add(RequestNameList[i]);
{ populate RequestNameStrings with a list of names }
CommandNameStrings := TStringList.Create;
for i := 0 to Integer(CMAX) - 1 do CommandNameStrings.Add(CommandNameList[i]);
{ this module only functions if we told the emulator to listen for remote commands }
if MainForm.RemotePort <> 0 then
with RcSocket do
begin
TBindingSocket(RcSocket).Address := MainForm.RemoteAddress;
Port := MainForm.RemotePort;
Active := True;
Open;
end;
end;
procedure TRemoteForm.RcSocketClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
var s: String;
begin
RcConnectedPanel.Color := clGreen;
RcConnectedPanel.Font.Color := clWhite;
with RcSocket.Socket do
begin
{ only work with a single connection - close any extra accepted ones }
if ActiveConnections > MAXCONNECTIONS then
begin
Connections[ActiveConnections - 1].Close;
end else
begin
RcConnectedPanel.Caption := IntToStr(ActiveConnections)+' connected (Port: '+IntToStr(MainForm.RemotePort)+')';
{ if we haven't closed this window once, display the window when a client connects, but don't take focus away from main window }
if (not gotClosed) and (not Visible) then
begin
MainForm.Show;
Show;
end;
{ send a hello identifier - this also helps some telnet clients that won't echo locally until they see some output }
s := 'EMHELLO'+#13+#10;
CmdCache[ActiveConnections - 1].ParserState := sAny;
CmdCache[ActiveConnections - 1].connId := ActiveConnections - 1;
SendResponse(ActiveConnections - 1, s[1],Length(s));
end;
end;
end;
procedure TRemoteForm.RcSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
if RcSocket.Socket.ActiveConnections = 1 then
begin
RcConnectedPanel.Caption := 'Disconnected (Port: '+IntToStr(MainForm.RemotePort)+')';
RcConnectedPanel.Color := clRed;
RcConnectedPanel.Font.Color := clSilver;
end else begin
RcConnectedPanel.Caption := IntToStr(RcSocket.Socket.ActiveConnections - 1)+' connected (Port: '+IntToStr(MainForm.RemotePort)+')';
end;
end;
{ queue a remote command for dispatch }
procedure TRemoteForm.EnqueueCmd (var cmd: TCmd);
label cleanup;
begin
if (cmd.ctype = cNone) then goto cleanup;
{ execute requests and commands immediately }
if cmd.ctype in [ cRequest, cCommand ] then
begin
ExecCmd(cmd);
goto cleanup;
end;
QueueTimer.Enabled := True;
{ queue keyboard input }
if CmdQueued < CMDQUEUESIZE then
begin
CmdQueue[CmdQueueWrite] := cmd;
Inc(CmdQueueWrite);
CmdQueueWrite := CmdQueueWrite mod CMDQUEUESIZE;
Inc(CmdQueued);
end;
cleanup:
fillchar(cmd, sizeof(cmd), 0);
end;
{ grab the next command and dispatch it }
procedure TRemoteForm.DequeueCmd;
var c: TCmd;
begin
if CmdQueued > 0 then
begin
c := CmdQueue[CmdQueueRead];
Inc(CmdQueueRead);
CmdQueueRead := CmdQueueRead mod CMDQUEUESIZE;
Dec(CmdQueued);
ExecCmd(c);
end;
if CmdQueued = 0 then QueueTimer.Enabled := False;
end;
{ parse and dispatch a remote command }
procedure TRemoteForm.ExecCmd(var c: TCmd);
var
n: integer;
ResponseStr: String;
i: integer;
vbuf: array[0..LCDSIZE + 4 - 1] of byte; { "VMEM" string + LCD memory }
begin
if c.paramcount > 0 then begin
for i:= 0 to c.paramcount do SerialForm.CasioRxHex.Lines.Add(c.params[i]);
end;
case c.ctype of
{ key entry }
cKey: begin
{ key code already specified }
if c.keycode <> 0 then dispatchKeyCode(c.keycode);
{ symbolic key name specified, look it up and dispatch the named key if found }
if c.name <> '' then
begin
n := KeyNameStrings.IndexOf(c.name);
if n >= 0 then dispatchKeyCode(KeyList[n]);
if c.name='NEWALL' then
begin
ResponseStr := 'REQUIRED=NEWALLYESIMSURE';
SendResponse(c.connId, ResponseStr[1], Length(ResponseStr));
end;
if c.name='WAKEUP' then
begin
CpuWakeup(False);
end;
if c.name='RESET' then
begin
ResetAll;
end;
end;
end; {cKey}
{ request: ask for some data }
cRequest: if c.name <> '' then begin
{ check if we recognise the request, index corresponds to the TRequestType enum }
n := RequestNameStrings.IndexOf(c.name);
ResponseStr := '';
if n >= 0 then case TRequestType(n) of
RPOWER: begin
ResponseStr := 'POWER=';
if (flag and SW_bit) <> 0 then
ResponseStr := ResponseStr + 'ON'
else
ResponseStr := ResponseStr + 'OFF';
end; { POWER? }
RPAUSE: begin
ResponseStr := 'PAUSE=';
if CpuStop then
ResponseStr := ResponseStr + 'ON'
else
ResponseStr := ResponseStr + 'OFF';
end; { PAUSE? }
RVMEM: begin
ResponseStr := 'VMEM';
Move(ResponseStr[1],vbuf,4);
Move(lcdimage,vbuf[4],LCDSIZE);
SendResponse(c.connId, vbuf, LCDSIZE + 4);
exit;
end; { VMEM? }
RSLEEP: begin
if (flag and APO_bit) <> 0 then
begin
ResponseStr := 'SLEEP=ON';
end else
begin
ResponseStr := 'SLEEP=OFF';
end;
end; {SLEEP?}
RVERSION: begin
ResponseStr := 'EMVERSION,'+PLATFORM_ID+','+VERSION_STR;
end; { VERSION? }
end; {case}
{ send response }
if ResponseStr <> '' then
SendResponse(c.connId, ResponseStr[1], Length(ResponseStr));
end; {cRequest}
{ command: do something }
cCommand: if c.name <> '' then begin
{ check if we recognise the request, index corresponds to the TCommandType enum }
n := CommandNameStrings.IndexOf(c.name);
ResponseStr := '';
if n >= 0 then case TCommandType(n) of
CPOWER: begin
ResponseStr := 'POWER=';
if c.paramcount > 0 then
begin
if c.params[0] = 'ON' then
begin
ResponseStr := ResponseStr + 'ON';
SetPower(true);
end else if c.params[0] = 'OFF' then
begin
SetPower(false);
ResponseStr := ResponseStr + 'OFF';
end;
end else if TogglePower then
ResponseStr := ResponseStr + 'ON'
else
ResponseStr := ResponseStr + 'OFF';
end; { POWER! }
CPAUSE: begin
ResponseStr := 'PAUSE=';
if c.paramcount > 0 then
begin
if c.params[0] = 'ON' then
begin
ResponseStr := ResponseStr + 'ON';
CpuStop := True;
end else if c.params[0] = 'OFF' then
begin
CpuStop := False;
ResponseStr := ResponseStr + 'OFF';
end;
end else
begin
CpuStop := not CpuStop;
if CpuStop then
ResponseStr := ResponseStr + 'ON'
else
ResponseStr := ResponseStr + 'OFF';
end;
end; { PAUSE! }
CSAVEMEM: begin
if SaveState(false, false) then
ResponseStr := 'SAVEMEM=OK'
else
ResponseStr := 'SAVEMEM=FAIL';
end; { SAVEMEM! }
CLOADMEM: begin
if LoadState(false, false) then
ResponseStr := 'LOADMEM=OK'
else
ResponseStr := 'LOADMEM=FAIL';
end; { LOADMEM! }
CRESET: begin
ResetAll;
ResponseStr := 'RESET=OK';
end; { RESET! }
CWAKEUP: begin
CpuWakeup(False);
ResponseStr := 'WAKEUP=OK';
end; { WAKEUP! }
end; {case}
{ send response }
if ResponseStr <> '' then
SendResponse(c.connId, ResponseStr[1], Length(ResponseStr));
end; { cCommand }
end;
end;
procedure TRemoteForm.SendResponse(connId: integer; var buf; len: integer);
begin
{ manually fed strings don't produce any response }
if connId = MAXCONNECTIONS then exit;
with RcSocket.Socket do
begin
try
if ActiveConnections > 0 then Connections[connId].SendBuf(buf, len);
except
RcSocket.Socket.Connections[connId].Close;
end;
end;
end;
{ run command parser over a string, and reset the parser at the end - }
{ one run is meant to be a complete session / set of commands }
procedure TRemoteForm.ParseString(s: string);
var b: array of byte;
begin
fillchar(cmdCache[MAXCONNECTIONS], sizeof(TCmd), 0);
SetLength(b, length(s));
Move(s[1],b[0],length(s));
QueueTimer.Enabled := true;
ParseBuf(b, length(s), cmdCache[MAXCONNECTIONS]);
fillchar(cmdCache[MAXCONNECTIONS], sizeof(TCmd), 0);
end;
{ run command parser over a buffer }
procedure TRemoteForm.ParseBuf(var buf: array of byte; len: integer; var cmd: TCmd);
var
c: char;
b: byte;
i, kc: integer;
sh: boolean;
label keydone, tokenjump, keyjump;
begin
for i:= 0 to len - 1 do
begin
b := buf[i];
c := UpCase(chr(b));
case cmd.ParserState of
{ looking for any characters }
sAny: begin
cmd.paramcount := 0;
cmd.ctype := cNone;
cmd.name := '';
{ simple enter, del, bs }
case b of
$08: begin cmd.ctype := cKey; cmd.keycode := KC_BS; end;
$09: begin cmd.ctype := cKey; cmd.keycode := KC_TAB; end;
$0d,$0a: begin cmd.ctype := cKey; cmd.keycode := KC_EXE; end;
$7f: begin cmd.ctype := cKey; cmd.keycode := KC_DEL; end;
end;
if cmd.ctype <> cNone then goto keydone;
{ Escape }
if c = #27 then
begin
cmd.name := '';
cmd.ParserState := sEsc;
continue;
end;
{ non-printable ASCII }
if (b < 32) or ( b > 126) then continue;
{ '<' = beginning of a command token, advance state }
if c = '<' then
begin
cmd.name := '';
cmd.ParserState := sToken;
continue;
end;
keyjump:
{ a valid keyboard key }
kc := GetCharacterCode(c, sh);
cmd.keycode := 0;
if (kc >0) then
begin
{ key needs prepended with shift, queue that first }
if sh then
begin
cmd.ctype := cKey;
cmd.keycode := KC_SHIFT;
EnqueueCmd(cmd);
end;
cmd.ctype := cKey;
cmd.keycode := kc;
end;
keydone:
{ command parsed, queue it for execution }
EnqueueCmd(cmd);
end; {sAny}
{ we are inside a <token> }
sToken: begin
{ a-z, 0-9: keep building token = command name }
if c in ['A'..'Z', '0'..'9'] then
begin
if Length(cmd.name) < MAXCMDLEN then cmd.name := cmd.name + c;
continue;
end;
tokenjump:
{ other identifiers }
case c of
{ space: we will now be passing parameters or adding parameters}
' ': with cmd do begin
if paramcount < MAXPARAMS then
begin
ParserState:= sParams;
{ do not introduce empty parameters with repeated spaces }
if (paramcount = 0) or (params[paramcount - 1] <> '')
then inc(paramcount);
params[paramcount - 1] := '';
continue;
end;
{ reset state from sParams to sToken - this happens if we exceed MAXPARAMS }
ParserState := sToken;
continue;
end;
{ '<' inside a token = we want a '<' entered and we escaped it with another '<' }
'<': begin
cmd.parserState := sAny;
{ short-circuit to process the key }
goto keyjump;
end;
{ <NAME?> is a request }
'?': begin
cmd.cType := cRequest;
continue;
end;
{ <NAME!> is a command }
'!': begin
cmd.cType := cCommand;
continue;
end;
{ end of token }
'>': begin
{ if it's not a request ('?') or command ('!') then it's a named key }
if not (cmd.cType in [ cRequest, cCommand ]) then cmd.ctype := cKey;
{ no key number, work with key name }
cmd.keycode := 0;
{ reset parser state }
cmd.ParserState := sAny;
EnqueueCmd(cmd);
end;
end; {case}
{ any other character }
cmd.ParserState := sAny;
end; {sToken}
sParams: begin
{ a-z, 0-9: keep building current parameter }
if c in ['A'..'Z', '0'..'9'] then with cmd do
begin
if Length(params[paramcount - 1]) < MAXPARAMLEN then
params[paramcount - 1] := params[paramcount - 1] + c;
continue;
end;
{ otherwise short-circuit to token end or extension }
goto tokenjump;
end; {sParams}
{ TODO: parse more complex sequences with parameters }
sEsc: begin
{ ESC + '[' = Control Sequence Introducer (CSI) }
if c = '[' then
begin
cmd.ParserState := sCsi;
continue;
end;
{ any other chatacter }
cmd.ParserState := sAny;
end; {sEsc}
{ some basic common CSI codes: cursor keys for now }
sCsi: begin
cmd.ctype := cNone;
case c of
'A': begin cmd.ctype := cKey; cmd.keycode := KC_UP; end;
'B': begin cmd.ctype := cKey; cmd.keycode := KC_DOWN; end;
{ I always lauged at how ANSI made sure that RIGHT goes before LEFT. }
{ It's actually Forward and Backward, but this only emphasises the sentiment }
'C': begin cmd.ctype := cKey; cmd.keycode := KC_RIGHT; end;
'D': begin cmd.ctype := cKey; cmd.keycode := KC_LEFT; end;
end;
cmd.ParserState := sAny;
if cmd.cType <> cNone then EnqueueCmd(cmd);
end; {sCsi}
end; {case}
end; {for}
end;
{ send a character to the keyboard }
procedure TRemoteForm.DispatchKeyCode(kc: integer);
begin
SendKeyCode(kc);
if kc = KC_BRK then CpuWakeup(False);
KeyUpTimer.Enabled := True;
end;
{ data has arrived at the socket }
procedure TRemoteForm.RcSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
hadData: boolean;
buf: array [0..RXBUFSIZE-1] of byte;
i,len: integer;
begin
hadData := false;
with RcSocket.Socket do
begin
if ActiveConnections > 0 then
for i:= 0 to (ActiveConnections - 1) do
begin
try
repeat
len := Connections[i].ReceiveBuf(buf, RXBUFSIZE);
if len > 0 then
begin
hadData := true;
CmdCache[i].connId := i;
parseBuf(buf, len, CmdCache[i]);
end;
until len < 1;
except
RcSocket.Socket.Connections[i].Close;
end;
if hadData and Visible then
begin
RcActiveLed.Color := clBlue;
RcActiveLed.Font.Color := clWhite;
end;
end;
end
end;
procedure TRemoteForm.RcSocketClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
{ silence the error }
ErrorCode := 0;
Socket.Close;
end;
procedure TRemoteForm.LedTimerTimer(Sender: TObject);
begin
RcActiveLed.Color := clBtnFace;
RcActiveLed.Font.Color := clWindowText;
end;
procedure TRemoteForm.FormShow(Sender: TObject);
begin
LedTimer.Enabled := True;
end;
procedure TRemoteForm.FormHide(Sender: TObject);
begin
LedTimer.Enabled := False;
end;
procedure TRemoteForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_F5 then Hide; { this is to allow toggling the window if it has focus }
if Key = VK_ESCAPE then Hide;
end;
procedure TRemoteForm.KeyUpTimerTimer(Sender: TObject);
begin
SendKeyCode(KC_NONE);
KeyUpTimer.Enabled := false;
end;
procedure TRemoteForm.FormDestroy(Sender: TObject);
begin
KeyNameStrings.Free;
RequestNameStrings.Free;
CommandNameStrings.Free;
end;
{ keep picking up requests from the queue }
procedure TRemoteForm.QueueTimerTimer(Sender: TObject);
begin
if not KeyUpTimer.Enabled then DequeueCmd;
end;
procedure TRemoteForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
gotClosed := true;
end;
end.