forked from cheat-engine/cheat-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotKeys.pas
executable file
·840 lines (672 loc) · 22.2 KB
/
HotKeys.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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
unit HotKeys;
{$MODE Delphi}
interface
uses
{$ifdef darwin}
macport, LCLType, math, machotkeys,
{$endif}
{$ifdef windows}
windows,
{$endif}
LCLIntf, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, registry, CEFuncProc, ExtCtrls, LResources,
comCtrls, menus, hotkeyhandler, MemoryRecordUnit, commonTypeDefs, strutils, betterControls;
type
{ THotKeyForm }
THotKeyForm = class(TForm)
btnApply: TButton;
btnCreateHotkey: TButton;
btnEditHotkey: TButton;
btnCancel: TButton;
btnOK: TButton;
Button2: TButton;
cbActivateSound: TComboBox;
cbDeactivateSound: TComboBox;
cbFreezedirection: TComboBox;
cbForceEnglishActivate: TCheckBox;
cbForceEnglishDeactivate: TCheckBox;
cbOnlyWhileDown: TCheckBox;
edtActivateText: TEdit;
edtDeactivateText: TEdit;
edtDescription: TEdit;
edtFreezeValue: TEdit;
edtHotkey: TEdit;
schImageList: TImageList;
Label1: TLabel;
Label2: TLabel;
lblActivateSound: TLabel;
lblDeactivateSound: TLabel;
lblID: TLabel;
ListView1: TListView;
miAddSound: TMenuItem;
miDelete: TMenuItem;
odWave: TOpenDialog;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
pmHotkeylist: TPopupMenu;
pmAddSound: TPopupMenu;
sbPlayActivate: TSpeedButton;
sbPlayDeactivate: TSpeedButton;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
procedure btnCreateHotkeyClick(Sender: TObject);
procedure btnEditHotkeyClick(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure cbActivateSoundChange(Sender: TObject);
procedure cbDeactivateSoundChange(Sender: TObject);
procedure cbForceEnglishActivateChange(Sender: TObject);
procedure cbFreezedirectionSelect(Sender: TObject);
procedure cbPlaySoundChange(Sender: TObject);
procedure edtHotkeyKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edtHotkeyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure miAddSoundClick(Sender: TObject);
procedure miDeleteClick(Sender: TObject);
procedure Panel2Resize(Sender: TObject);
procedure pmHotkeylistPopup(Sender: TObject);
procedure sbPlayActivateClick(Sender: TObject);
procedure sbPlayDeactivateClick(Sender: TObject);
private
{ Private declarations }
keys: tkeycombo;
editHotkey: boolean;
fmemrec: TMemoryRecord;
procedure SpeakText(s:string; forceEnglish: boolean=false);
procedure SetMemrec(x: TMemoryRecord);
function HotkeyActionToText(a: TMemrecHotkeyAction): string;
function getHotkeyAction: TMemrecHotkeyAction;
function getBtnOKCustomButton: TCustomButton;
public
{ Public declarations }
published
property memrec: TMemoryRecord read fmemrec write SetMemrec;
property BitBtn1: TCustomButton read getBtnOKCustomButton; //compatibility with older versions
end;
implementation
uses MainUnit, {$ifdef windows}trainergenerator,{$endif} luafile, LuaHandler, DPIHelper;
resourcestring
rsHotkeyID = 'Hotkey ID=%s';
rsToggleScript = 'Toggle script';
rsEnableScript = 'Enable script';
rsDisableScript = 'Disable script';
rsToggleFreeze = 'Toggle freeze';
rsToggleFreezeAndAllowIncrease = 'Toggle freeze and allow increase';
rsToggleFreezeAndAllowDecrease = 'Toggle freeze and allow decrease';
rsFreeze = 'Freeze';
rsUnfreeze = 'Unfreeze';
rsSetValueTo = 'Set value to:';
rsDecreaseValueWith = 'Decrease value with:';
rsIncreaseValueWith = 'Increase value with:';
rsSpeakText = 'Speak Text';
rsTextToSpeechHint = 'The text to speak'#13#10'{Description} = The description of the hotkey'#13#10'{MRDescription} = The description field of the memory record'#13#10'{MRValue} = The value of the memory record';
rsDefaultActivated = '%s Activated';
rsDefaultDeactivated = '%s Deactivated';
rsDeactivateOnRelease = 'Deactivate on release';
rsRestoreToOriginalOnRelease = 'Restore to original on release';
function THotkeyform.getBtnOKCustomButton: TCustomButton;
begin
result:=btnOK as TCustomButton;
end;
function THotkeyform.getHotkeyAction: TMemrecHotkeyAction;
begin
result:=mrhToggleActivation;
if fmemrec.vartype=vtAutoAssembler then
begin
case cbFreezedirection.ItemIndex of
0: result:=mrhToggleActivation;
1: result:=mrhActivate;
2: result:=mrhDeactivate;
end;
end
else
begin
case cbFreezedirection.ItemIndex of
0: result:=mrhToggleActivation;
1: result:=mrhToggleActivationAllowIncrease;
2: result:=mrhToggleActivationAllowDecrease;
3: result:=mrhActivate;
4: result:=mrhDeactivate;
5: result:=mrhSetValue;
6: result:=mrhDecreaseValue;
7: result:=mrhIncreaseValue;
end;
end;
end;
function THotkeyform.HotkeyActionToText(a: TMemrecHotkeyAction): string;
begin
{
Toggle freeze/Toggle activated
Toggle freeze and allow increase
Toggle freeze and allow decrease
Set value to:
Decrease value with:
Increase value with:
}
result:='';
if memrec.VarType=vtAutoAssembler then
begin
case a of
mrhToggleActivation: result:=cbFreezedirection.Items[0];
mrhActivate: result:=cbFreezedirection.items[1];
mrhDeactivate: result:=cbFreezedirection.items[2];
end;
end
else
begin
case a of
mrhToggleActivation: result:=cbFreezedirection.Items[0];
mrhToggleActivationAllowIncrease: result:=cbFreezedirection.Items[1];
mrhToggleActivationAllowDecrease: result:=cbFreezedirection.Items[2];
mrhActivate: result:=cbFreezedirection.items[3];
mrhDeactivate: result:=cbFreezedirection.items[4];
mrhSetValue: result:=cbFreezedirection.Items[5];
mrhDecreaseValue: result:=cbFreezedirection.Items[6];
mrhIncreaseValue: result:=cbFreezedirection.Items[7];
end;
end;
end;
procedure THotkeyform.SetMemrec(x: TMemoryRecord);
var i: integer;
li: TListItem;
hk: TMemoryRecordHotkey;
begin
if x<>nil then
begin
if x.VarType=vtAutoAssembler then
begin
cbFreezedirection.Clear;
cbFreezedirection.Items.add(rsToggleScript);
cbFreezedirection.items.add(rsEnableScript);
cbFreezedirection.items.add(rsDisableScript);
cbFreezedirection.ItemIndex:=0;
edtFreezeValue.enabled:=false;
end;
listview1.clear;
fmemrec:=x;
caption:=caption+' : '+memrec.Description;
for i:=0 to memrec.HotkeyCount-1 do
begin
hk:=memrec.Hotkey[i];
begin
li:=listview1.Items.Add;
li.caption:=ConvertKeyComboToString(hk.keys);
li.SubItems.Add(HotkeyActionToText(hk.action));
li.SubItems.Add(hk.value);
li.SubItems.Add(hk.description);
lblid.caption:=inttostr(hk.id);
li.Data:=hk;
end;
end;
end;
end;
procedure THotKeyForm.btnCreateHotkeyClick(Sender: TObject);
var li: TListitem;
i: integer;
begin
for i:=0 to length(keys)-1 do
keys[i]:=0;
pagecontrol1.ActivePage:=tabsheet2;
li:=listview1.items.add;
li.SubItems.add(''); //on hotkey
li.SubItems.add(''); //value
li.SubItems.add(''); //description
li.Data:=nil;
li.selected:=true;
edtHotkey.text:='';
cbFreezedirection.ItemIndex:=0;
edtFreezeValue.text:='';
editHotkey:=true;
listview1.Enabled:=false;
if visible then
edtHotkey.SetFocus;
cbFreezedirectionSelect(cbFreezedirection);
cbActivateSound.itemindex:=-1;
cbActivateSoundChange(cbActivateSound);
cbDeactivateSound.itemindex:=-1;
cbDeactivateSoundChange(cbDeactivateSound);
end;
procedure THotKeyForm.btnEditHotkeyClick(Sender: TObject);
var
s: TListitem;
i: integer;
hk: TMemoryRecordHotkey;
begin
s:=listview1.selected;
if s=nil then
begin
i:=listview1.itemindex;
if i=-1 then exit;
s:=listview1.items[i];
end;
if s=nil then exit;
pagecontrol1.ActivePage:=tabsheet2;
listview1.Enabled:=false;
keys:=TMemoryRecordHotkey(listview1.selected.data).keys;
edtHotkey.text:=ConvertKeyComboToString(keys);
cbFreezedirection.ItemIndex:=cbFreezedirection.Items.IndexOf(listview1.selected.SubItems[0]);
edtFreezeValue.text:=listview1.selected.subitems[1];
edtDescription.text:=listview1.selected.subitems[2];
if visible then
edtHotkey.SetFocus;
editHotkey:=true;
hk:=TMemoryRecordHotkey(listview1.Selected.data);
if hk.ActivateSoundFlag=hksPlaySound then
cbActivateSound.ItemIndex:=cbActivateSound.Items.IndexOf(hk.activateSound)
else
begin
cbActivateSound.ItemIndex:=cbActivateSound.items.count-1;
cbForceEnglishActivate.checked:=hk.ActivateSoundFlag=hksSpeakTextEnglish;
edtActivateText.Text:=hk.activateSound;
end;
if hk.DeactivateSoundFlag=hksPlaySound then
cbDeactivateSound.ItemIndex:=cbDeactivateSound.Items.IndexOf(hk.deactivateSound)
else
begin
cbDeactivateSound.ItemIndex:=cbActivateSound.items.count-1;
cbForceEnglishDeactivate.checked:=hk.DeactivateSoundFlag=hksSpeakTextEnglish;
edtDeactivateText.Text:=hk.deactivateSound;
end;
cbActivateSoundChange(cbActivateSound);
cbDeactivateSoundChange(cbDeactivateSound);
cbFreezedirection.OnSelect(cbFreezedirection);
cbOnlyWhileDown.checked:=hk.OnlyWhileDown;
end;
procedure THotKeyForm.btnApplyClick(Sender: TObject);
var hk: TMemoryRecordHotkey;
begin
if editHotkey and (listview1.Selected.data<>nil) then
begin
hk:=TMemoryRecordHotkey(listview1.Selected.data);
hk.keys:=keys;
hk.action:=getHotkeyAction;
hk.value:=edtFreezeValue.text;
hk.fdescription:=edtDescription.text;
hk.fOnlyWhileDown:=cbOnlyWhileDown.checked;
hk.registerkeys;
end
else
hk:=memrec.Addhotkey(keys, getHotkeyAction, edtFreezeValue.text, edtDescription.text, cbOnlyWhileDown.checked );
if cbActivateSound.ItemIndex=cbActivateSound.items.count-1 then
begin
if cbForceEnglishActivate.Checked then
hk.ActivateSoundFlag:=hksSpeakTextEnglish
else
hk.ActivateSoundFlag:=hksSpeakText;
hk.activateSound:=edtActivateText.Text;
end
else
begin
hk.ActivateSoundFlag:=hksPlaySound;
hk.activateSound:=cbActivateSound.Text;
end;
if cbDeactivateSound.ItemIndex=cbDeactivateSound.items.count-1 then
begin
if cbForceEnglishDeactivate.Checked then
hk.DeactivateSoundFlag:=hksSpeakTextEnglish
else
hk.DeactivateSoundFlag:=hksSpeakText;
hk.deactivatesound:=edtDeactivateText.Text;
end
else
begin
hk.DeactivateSoundFlag:=hksPlaySound;
hk.deactivatesound:=cbDeactivateSound.Text;
end;
listview1.selected.Caption:=edtHotkey.Text;
listview1.Selected.SubItems[0]:=cbFreezedirection.Text;
listview1.selected.subitems[1]:=edtFreezeValue.text;
listview1.selected.subitems[2]:=edtDescription.text;
listview1.Selected.data:=hk;
pagecontrol1.ActivePage:=tabsheet1;
listview1.Enabled:=true;
edithotkey:=false;
end;
procedure THotKeyForm.btnCancelClick(Sender: TObject);
begin
editHotkey:=false;
if (listview1.Selected<>nil) and (listview1.selected.data=nil) then //created hotkey
listview1.selected.delete;
pagecontrol1.ActivePage:=tabsheet1;
listview1.Enabled:=true;
end;
procedure THotKeyForm.btnOKClick(Sender: TObject);
begin
if edithotkey then
btnApply.click;
close;
end;
procedure THotKeyForm.Button2Click(Sender: TObject);
begin
zeromemory(@keys,sizeof(TKeyCombo));
edtHotkey.Text:=ConvertKeyComboToString(keys);
edtHotkey.SetFocus;
end;
procedure THotKeyForm.cbActivateSoundChange(Sender: TObject);
begin
edtActivateText.visible:=cbActivateSound.ItemIndex=cbActivateSound.Items.Count-1;
cbForceEnglishActivate.visible:=edtActivateText.visible;
end;
procedure THotKeyForm.cbDeactivateSoundChange(Sender: TObject);
begin
edtDeactivateText.visible:=cbDeactivateSound.ItemIndex=cbDeactivateSound.Items.Count-1;
cbForceEnglishDeactivate.visible:=edtDeactivateText.Visible;
end;
procedure THotKeyForm.cbForceEnglishActivateChange(Sender: TObject);
begin
end;
procedure THotKeyForm.cbFreezedirectionSelect(Sender: TObject);
var
onpossible: boolean;
offpossible: boolean;
begin
edtFreezeValue.enabled:=(memrec.VarType<>vtAutoAssembler) and (cbFreezeDirection.itemindex >=5); //set value, increase by and decrease by
if (memrec.VarType=vtAutoAssembler) then
begin
onpossible:=cbFreezeDirection.itemindex in [0,1];
offpossible:=cbFreezeDirection.itemindex in [0,2];
if onpossible then
begin
cbOnlyWhileDown.Caption:=rsDeactivateOnRelease;
cbOnlyWhileDown.visible:=true;
end
else
cbOnlyWhileDown.visible:=false;
end
else
begin
onpossible:=cbFreezeDirection.itemindex in [0,1,2,3,5,6,7];
offpossible:=cbFreezeDirection.itemindex in [0,1,2,4];
if cbFreezeDirection.itemindex in [0,1,2,3,5] then
begin
case cbFreezeDirection.itemindex of
0, 1, 2, 3: cbOnlyWhileDown.Caption:=rsDeactivateOnRelease;
5: cbOnlyWhileDown.Caption:=rsRestoreToOriginalOnRelease;
end;
cbOnlyWhileDown.visible:=true;
end
else
cbOnlyWhileDown.visible:=false;
end;
lblActivateSound.enabled:=onpossible;
cbActivateSound.enabled:=onpossible;
sbPlayActivate.enabled:=onpossible;
lblDeactivateSound.enabled:=offpossible;
cbDeactivateSound.enabled:=offpossible;
sbPlayDeactivate.enabled:=offpossible;
end;
procedure THotKeyForm.cbPlaySoundChange(Sender: TObject);
begin
cbFreezedirectionSelect(cbFreezedirection);
end;
function isModifier(k: word): boolean;
begin
result:=false;
case k of
vk_lwin, vk_rwin, vk_shift,vk_lshift,
vk_rshift, VK_CAPITAL, VK_MENU, vk_LMENU,
vk_RMENU, VK_CONTROL, VK_LCONTROL, VK_RCONTROL:
result:=true;
end;
end;
procedure THotKeyForm.edtHotkeyKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i: integer;
begin
{$ifdef darwin}
if not isModifier(key) then
begin
//there can be only one non-modifier
for i:=0 to 4 do
begin
if keys[i]=0 then break;
if not isModifier(keys[i]) then
begin
key:=0; //do not add
break;
end;
end;
end;
{$endif}
if keys[4]=0 then
begin
for i:=0 to 4 do
if keys[i]=0 then
begin
keys[i]:=key;
break;
end else
if keys[i]=key then break;
end;
edtHotkey.Text:=ConvertKeyComboToString(keys);
key:=0;
end;
procedure THotKeyForm.edtHotkeyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var key: word;
begin
key:=0;
case button of
mbMiddle: key:=VK_MBUTTON;
mbExtra1: key:=VK_XBUTTON1;
mbExtra2: key:=VK_XBUTTON2;
end;
if key<>0 then
edtHotkeyKeyDown(edtHotkey, key, shift);
end;
procedure THotKeyForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
fmemrec.endEdit;
CloseAction:=caFree;
end;
procedure THotKeyForm.FormCreate(Sender: TObject);
var lblLimiteHotkeySupport: tlabel;
begin
{$ifdef darwin}
if loadMacHotkeyFunctions=false then
begin
lblLimiteHotkeySupport:=tlabel.create(self);
lblLimiteHotkeySupport.caption:='Limited hotkey support. No character keys supported';
lblLimiteHotkeySupport.font.color:=clRed;
lblLimiteHotkeySupport.align:=alBottom;
lblLimiteHotkeySupport.parent:=self;
end;
{$endif}
edtActivateText.Hint:=rsTextToSpeechHint; //make it easier for translators
edtDeactivateText.Hint:=edtActivateText.Hint;
edtActivateText.Text:=format(rsDefaultActivated, ['{MRDescription}']);
edtDeactivateText.Text:=format(rsDefaultDeactivated, ['{MRDescription}']);
edtActivateText.ShowHint:=true;
edtDeactivateText.ShowHint:=true;
pagecontrol1.ActivePage:=tabsheet1;
with cbFreezedirection.Items do
begin
clear;
add(rsToggleFreeze);
add(rsToggleFreezeAndAllowIncrease);
add(rsToggleFreezeAndAllowDecrease);
add(rsFreeze);
add(rsUnfreeze);
add(rsSetValueTo);
add(rsDecreaseValueWith);
add(rsIncreaseValueWith);
end;
cbFreezedirection.itemindex:=0;
cbActivateSound.Items.Clear;
cbDeactivateSound.Items.Clear;
cbActivateSound.Items.add('');
cbDeactivateSound.Items.add('');
{$ifdef windows}
FillSoundList(cbActivateSound.Items);
FillSoundList(cbDeactivateSound.Items);
cbActivateSound.Items.Add(rsSpeakText);
cbDeactivateSound.Items.Add(rsSpeakText);
{$else}
cbActivateSound.Enabled:=false;
cbDeactivateSound.Enabled:=false;
sbPlayActivate.enabled:=false;
sbPlayDeactivate.enabled:=false;
{$endif}
end;
procedure THotKeyForm.FormShow(Sender: TObject);
var
i, maxwidth: integer;
s: string;
{$ifdef windows}
cbi: TComboboxInfo;
{$endif}
begin
PageControl1.PageIndex:=1;
cbActivateSound.Top:=edtHotkey.Top;
AdjustSpeedButtonSize(sbPlayActivate);
AdjustSpeedButtonSize(sbPlayDeactivate);
maxwidth:=0;
for i:=0 to cbFreezedirection.Items.Count-1 do
begin
s:=cbFreezedirection.Items[i];
maxwidth:=max(maxwidth, Canvas.TextWidth(s));
end;
{$ifdef windows}
cbi.cbSize:=sizeof(cbi);
if GetComboBoxInfo(cbFreezedirection.Handle, @cbi) then
begin
i:=maxwidth-(cbi.rcItem.Right-cbi.rcItem.Left)+4;
cbFreezedirection.width:=cbFreezedirection.width+i;
end
else
{$endif}
cbFreezedirection.width:=maxwidth+16;
maxwidth:=0;
for i:=0 to cbActivateSound.Items.Count-1 do
begin
s:=cbActivateSound.Items[i];
maxwidth:=max(maxwidth, Canvas.TextWidth(s));
end;
maxwidth:=max(maxwidth, canvas.TextWidth(edtActivateText.Text));
{$ifdef windows}
cbi.cbSize:=sizeof(cbi);
if GetComboBoxInfo(cbActivateSound.Handle, @cbi) then
begin
i:=maxwidth-(cbi.rcItem.Right-cbi.rcItem.Left)+4;
cbActivateSound.width:=cbActivateSound.width+i;
end
else
{$endif}
cbActivateSound.width:=maxwidth+16;
if cbFreezedirection.width>edtHotkey.Width then
edtHotkey.Width:=cbFreezedirection.width;
constraints.MinWidth:=width;
Constraints.MinHeight:=height; //panel2.height+panel1.Height+3*edtDescription.Height;
cbActivateSoundChange(cbActivateSound);
cbDeactivateSoundChange(cbDeactivateSound);
PageControl1.PageIndex:=0;
// autosize:=false;
if editHotkey then
begin
PageControl1.PageIndex:=1;
edtHotkey.SetFocus;
end;
// panel1.Constraints.MinHeight:=btnCancel.Top+btnCancel.Height+2;
end;
procedure THotKeyForm.ListView1DblClick(Sender: TObject);
begin
if btnEditHotkey.enabled then
btnEditHotkey.click;
end;
procedure THotKeyForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
btnEditHotkey.enabled:=selected;
if (listview1.selected<>nil) and (listview1.selected.data<>nil) then
lblid.caption:=Format(rsHotkeyID, [inttostr(TMemoryRecordHotkey(listview1.selected.data).id)])
else
lblid.caption:='';
end;
procedure THotKeyForm.miAddSoundClick(Sender: TObject);
var
i: integer;
s: tmemorystream;
lf: TLuafile;
oldactivate, olddeactivate: string;
begin
odwave.InitialDir:=GetCEdir;
if odwave.execute then
begin
for i:=0 to odwave.Files.Count-1 do
begin
s := TMemorystream.Create;
try
s.LoadFromFile(odwave.files[i]);
lf := TLuaFile.Create(extractfilename(odwave.files[i]), s);
MainForm.LuaFiles.Add(lf);
finally
s.free;
end;
end;
oldactivate:=cbActivateSound.text;
olddeactivate:=cbDeactivateSound.Text;
{$ifdef windows}
FillSoundList(cbActivateSound.Items);
FillSoundList(cbDeactivateSound.Items);
{$endif}
cbActivateSound.Items.Add(rsSpeakText);
cbDeactivateSound.Items.Add(rsSpeakText);
cbActivateSound.Itemindex:=cbActivateSound.Items.IndexOf(oldactivate);
cbDeactivateSound.Itemindex:=cbActivateSound.Items.IndexOf(olddeactivate);
end;
end;
procedure THotKeyForm.miDeleteClick(Sender: TObject);
var hk: TMemoryRecordHotkey;
begin
if listview1.enabled and (listview1.Selected<>nil) then
begin
hk:=TMemoryRecordHotkey(listview1.selected.data);
hk.free;
listview1.selected.delete;
end;
end;
procedure THotKeyForm.Panel2Resize(Sender: TObject);
begin
end;
procedure THotKeyForm.pmHotkeylistPopup(Sender: TObject);
begin
midelete.visible:=listview1.enabled and (listview1.Selected<>nil);
end;
procedure THotKeyForm.SpeakText(s:string; forceEnglish: boolean=false);
begin
s:=StringReplace(s,'{MRDescription}', memrec.Description,[rfIgnoreCase, rfReplaceAll]);
s:=StringReplace(s,'{Description}', edtDescription.Text, [rfIgnoreCase, rfReplaceAll]);
if forceEnglish then
LUA_DoScript('speakEnglish([['+s+']])')
else
LUA_DoScript('speak([['+s+']])');
end;
procedure THotKeyForm.sbPlayActivateClick(Sender: TObject);
begin
if cbActivateSound.ItemIndex=cbActivateSound.Items.Count-1 then
SpeakText(edtActivateText.text, cbForceEnglishActivate.Checked)
else
LUA_DoScript('playSound(findTableFile([['+cbActivateSound.Text+']]))');
end;
procedure THotKeyForm.sbPlayDeactivateClick(Sender: TObject);
begin
if cbDeactivateSound.ItemIndex=cbDeactivateSound.Items.Count-1 then
SpeakText(edtDeactivateText.text, cbForceEnglishDeactivate.Checked)
else
LUA_DoScript('playSound(findTableFile([['+cbDeactivateSound.Text+']]))');
end;
initialization
{$i HotKeys.lrs}
end.