-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnScreenKeyboard.lcb
3347 lines (2983 loc) · 222 KB
/
OnScreenKeyboard.lcb
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Copyright (C) 2023 Paul McClernan for OpenXTalk
This widget displays an on-screen keyboard.
*/
widget org.openxtalk.widget.onscreenkeyboard
/**
Name: keyDown
Type: message
Syntax: keyDown pKey
Summary: sent when a key is press on the keyboard while the widget has focus
Example:
on keyDown pKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do keyDown && pKey in me
end keyDown
Description:
The keyDown message is sent by the scripting engine, not from Extension Builder VM,
when a key is press on the keyboard. When the cursor enters the widget the widget
becomes the focusedObject and traversalOn is set to true, which are needed for
the widget to respond to input from the keyboard.
Name: keyUp
Type: message
Syntax: keyUp pKey
Summary: sent when a key is released on the keyboard while the widget has focus
Example:
on keyUp pKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do keyUp && pKey in me
end keyUp
Description:
The keyUp message is sent by the scripting engine, not from Extension Builder VM,
when a key is press on the keyboard. When the cursor enters the widget the widget
becomes the focusedObject and traversalOn is set to true, which are needed for
the widget to respond to input from the keyboard.
Name: commandKeyDown
Type: message
Syntax: commandKeyDown pKey
Summary: sent when a key is press on the keyboard while the widget has focus
Example:
on commandKeyDown pKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do commandKeyDown && pKey in me
end commandKeyDown
Description:
The commandKeyDown message is sent by the scripting engine, not from Extension Builder VM,
when a key is press on the keyboard. When the cursor enters the widget the widget
becomes the focusedObject and traversalOn is set to true, which are needed for
the widget to respond to input from the keyboard. Note that there is no commandKeyUp
coorisponding message sent, wHen the on commandKeyDown handler is used the input
acts like a momentary switch. Use keyDown,keyUp, rawKeyDown, rawKeyUp in
conjunction with the commandKey() function for more control.
Name: optionKeyDown
Type: message
Syntax: optionKeyDown pKey
Summary: sent when a key is press on the keyboard while the widget has focus
Example:
on optionKeyDown pKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do optionKeyDown && pKey in me
end optionKeyDown
Description:
The optionKeyDown message is sent by the scripting engine, not from Extension Builder VM,
when a key is press on the keyboard. When the cursor enters the widget the widget
becomes the focusedObject and traversalOn is set to true, which are needed for
the widget to respond to input from the keyboard. Note that there is no optionKeyUp
coorisponding message sent, wHen the on optionKeyDown handler is used the input
acts like a momentary switch. Use keyDown,keyUp, rawKeyDown, rawKeyUp in
conjunction with the optionKeyDown() funcion for more control.
Name: altKeyDown
Syntax: altKeyDown pKey
Type: message
Example:
on altKeyDown pKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do altKeyDown && pKey in me
end altKeyDown
Name: controlKeyDown
Syntax: controlKey pKey
Type: message
Example:
on controlKeyDown pKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do controlKey && pKey in me
end controlKeyDown
Name: functionKey
Type: message
Syntax: functionKey pKey
Summary: sent when a function key is press on the keyboard while the widget has focus
Example:
on functionKey pFkeyNum
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do functionKey && pFkeyNum in me
end functionKey
Description:
The functionKey message is sent by the scripting engine, not from Extension Builder VM,
when a key is press on the keyboard. When the cursor enters the widget the widget
becomes the focusedObject and traversalOn is set to true, which are needed for
the widget to respond to input from the keyboard. Note that wHen the on functionKey
handler is used the input acts like a momentary switch. Use rawKeyDown and rawKeyUp
for finer control over functionKeya input.
Name: rawKeyDown
Type: message
Syntax: rawKeyDown pKeyCode
Example:
on rawKeyDown pKeyCode
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do rawKeyDown && pKeyCode in me
end rawKeyDown
Name: rawKeyUp
Type: message
Syntax: rawKeyUp pKeyCode
Example:
on rawKeyUp pKeyCode
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do rawKeyUp && pKeyCode in me
end rawKeyUp
Name: virtualKeyDown
Type: message
Syntax: virtualKeyDown pKey
Example:
on virtualKeyDown pKey
put virtualKeyDown && pKey
end virtualKeyDown
Summary: sent when a key is press on the on-screen keyboard while the widget has focus
Name: virtualKeyUp
Type: message
Syntax: virtualKeyUp pKey
Example:
on virtualKeyUp pKey
put virtualKeyUp && pKey
end virtualKeyUp
Summary: sent when a key is released on the on-screen keyboard while the widget has focus
Name: arrowKey
Type: message
Syntax: arrowKey pDirection
Example:
on arrowKey pDirection
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do arrowKey && pDirection in me
end arrowKey
Name: enterKey
Type: message
Syntax: enterKey
Example:
on enterKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do enterKey in me
end enterKey
Name: returnKey
Type: message
Syntax: returnKey
Example:
on returnKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do returnKey in me
end returnKey
Name: tabKey
Type: message
Syntax: tabKey
Example:
on tabKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do tabKey in me
end tabKey
Name: escapeKey
Type: message
Syntax: escapeKey
Example:
on escapeKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do escapeKey in me
end escapeKey
Name: backspaceKey
Type: message
Syntax: backspaceKey
Example:
on backspaceKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do backspaceKey in me
end backspaceKey
Name: deleteKey
Type: message
Syntax: deleteKey
Example:
on deleteKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do deleteKey in me
end deleteKey
Name: cutKey
Type: message
Syntax: cutKey
Example:
on cutKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do cutKey in me --- should be same as doing 'command+x' in the widget
end cutKey
Name: copyKey
Type: message
Syntax: copyKey
Example:
on copyKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do copyKey in me --- should be same as doing 'command+c' in the widget
end copyKey
Name: pasteKey
Type: message
Syntax: pasteKey
Example:
on pasteKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do pasteKey in me --- should be same as doing 'command+v' in the widget
end pasteKey
Name: undoKey
Type: message
Syntax: undoKey
Example:
on undoKey
--- use 'do' 'in widget' to pass the key input message into the keyboard widget
do undoKey in me --- should be same as doing 'command+z' in the widget
end undoKey
Name: backKey
Type: message
Name: mouseMove
Type: message
Name: mouseDown
Type: message
Name: mouseUp
Type: message
Name: mouseRelease
Type: message
*/
-- dependency declarations
use com.livecode.canvas
use com.livecode.library.canvas
use com.livecode.widget
use com.livecode.engine
use com.livecode.library.widgetutils
use com.livecode.char
-- adding metadata to ensure the extension displays correctly in livecode
metadata title is "OnScreenkeyboard"
metadata author is "Paul McClernan"
metadata version is "1.0.0"
metadata preferredSize is "866,280"
metadata svgicon is "M19,10H17V8H19M19,13H17V11H19M16,10H14V8H16M16,13H14V11H16M16,17H8V15H16M7,10H5V8H7M7,13H5V11H7M8,11H10V13H8M8,8H10V10H8M11,11H13V13H11M11,8H13V10H11M20,5H4C2.89,5 2,5.89 2,7V17A2,2 0 0,0 4,19H20A2,2 0 0,0 22,17V7C22,5.89 21.1,5 20,5Z"
private variable mKeyboardBtns as List
private variable mModifierBtns as List
private variable mArrowKeys as List
private variable mPageKeys as List
private variable mNumPadKeys as List
private variable mFunctionKeys as List
private variable mMediaKeys as List
private variable mLEDIndicators as List
private variable mBorderPath as String
/**
Syntax:
set the foregroundColor of <widget> to <pColor>
get the foregroundColor of <widget>
Summary: Determines the color of key labels when not highlighted.
Description:
Use the <foregroundColor> property to set the color of keys label, when the key
isn't highlighted.
*/
metadata foregroundColor.editor is "com.livecode.pi.color"
metadata foregroundColor.default is ""
metadata foregroundColor.section is "Colors"
metadata foregroundColor.label is "key labels color"
private variable mColor as Color
/**
Syntax:
set the backgroundColor of <widget> to <pColor>
get the backgroundColor of <widget>
Summary: Determines the back fill color of the keyboard.
Description:
Use the <backgroundColor> property to set the color of back fill color of the keyboard.
*/
metadata backgroundColor.editor is "com.livecode.pi.color"
metadata backgroundColor.default is ""
metadata backgroundColor.section is "Colors"
metadata backgroundColor.label is "Background fill"
private variable mBackColor as Color
/**
Syntax:
set the borderColor of <widget> to <pColor>
get the borderColor of <widget>
Summary: Determines the color of the keyboards outline.
Description:
Use the <borderColor> property to set the color of the keyboards outline.
*/
metadata borderColor.editor is "com.livecode.pi.color"
metadata borderColor.section is "Colors"
metadata borderColor.label is "outline color"
private variable mStrokeColor as Color
metadata highlightColor.editor is "com.livecode.pi.color"
metadata highlightColor.section is "Colors"
metadata highlightColor.label is "Hilite color"
private variable mHiliteColor as Color
-- property maintainAspectRatio get mMaintainAspectRatio set setMaintainAspectRatio
private variable mMaintainAspectRatio as Boolean
-- public handler setMaintainAspectRatio(in pBoolean as Boolean)
-- put pBoolean into mMaintainAspectRatio
-- redraw all
-- end handler
/**
Syntax:
set the opaque of <widget> to <pColor>
get the opaque of <widget>
Summary: Determines the widget's bottom layer of the keyboard is filled with a background color.
Description:
Use the <opaque> property to set the bottom layer of the keyboard to be filled with a background color.
*/
property opaque get mOpaque set mOpaque
metadata opaque.default is "true"
metadata opaque.section is "Basic"
metadata opaque.label is "Opaque"
private variable mOpaque as Boolean
/**
Syntax:
set the strokeWidth of <widget> to <pStrokeSize>
get the stroke of <widget>
Summary: Determines the thickness of keyboard shapes outlines.
Description:
Use the <strokeWidth> property to the thickness of keyboard shapes outlines.
*/
property strokeWidth get mStrokeWidth set setStrokeWidth
metadata strokeWidth.editor is "com.livecode.pi.number"
metadata strokeWidth.label is "Stroke width"
metadata strokeWidth.section is "Basic"
metadata strokeWidth.default is "1"
private variable mStrokeWidth as Number
public handler setStrokeWidth (in pStrokeWidth as Number) returns nothing
put pStrokeWidth into mStrokeWidth
OnGeometryChanged()
redraw all
end handler
public handler getStrokeWidth() returns String
return mStrokeWidth
end handler
property toggleVKeyUp get mToggleVKeyUp set setToggleVKeyUp
metadata toggleVKeyUp.default is "false"
private variable mToggleVKeyUp as Boolean
public handler setToggleVKeyUp(in pShow as Boolean)
put pShow into mToggleVKeyUp
redraw all
return mToggleVKeyUp
end handler
property antialiasing get mToggleAntiAlias set setToggleAntiAlias
metadata antialiasing.default is "false"
metadata antialiasing.label is "Antialias"
metadata antialiasing.section is "Basic"
private variable mToggleAntiAlias as Boolean
public handler setToggleAntiAlias(in pAntiAlias as Boolean)
put pAntiAlias into mToggleAntiAlias
redraw all
return mToggleAntiAlias
end handler
property toggleMediaKeys get mToggleMediaKeys set setShowMediaKeys
metadata toggleMediaKeys.default is "false"
private variable mToggleMediaKeys as Boolean
public handler setShowMediaKeys(in pShow as Boolean)
put pShow into mToggleMediaKeys
redraw all
return mToggleMediaKeys
end handler
property toggleLEDs get mToggleLEDs set setToggleLEDs
metadata toggleLEDs.default is "true"
private variable mToggleLEDs as Boolean
public handler setToggleLEDs(in pShow as Boolean)
put pShow into mToggleLEDs
redraw all
return mToggleLEDs
end handler
/**
Syntax:
set the keyboardScale of <widget> to <pColor>
get the keyboardScale of <widget>
Summary: Determines the color of key label fills.
Description:
Use the <labelColor> property to set the color of keys label, when the key
isn't highlighted.
*/
property keyboardScale get getKeyboardScale set setKeyboardScale
metadata keyboardScale.editor is "com.livecode.pi.number"
metadata keyboardScale.label is "Scale"
metadata keyboardScale.default is "0.5"
private variable mHorizScale as Number
private variable mVertScale as Number
public handler setKeyboardScale(in pScale as Number) returns nothing
put pScale into mHorizScale
put pScale into mVertScale
redraw all
return
end handler
private variable mYOffset as Number
private variable mXOffset as Number
public handler OnGeometryChanged()
variable tRect
variable tKeyboardRect
variable tHorizPercentage as Number
variable tVertPercentage as Number
put my bounds into tRect
-- log [ my pixel scale]
put the bounding box of path mBorderPath into tKeyboardRect
put (the right of tRect / (the right of tKeyboardRect + (mStrokeWidth * 2) +2 )) into tHorizPercentage -- * mHorizScale]
put (the bottom of tRect / (the bottom of tKeyboardRect + (mStrokeWidth * 2) +2 )) into tVertPercentage -- * mHorizScale]
if tVertPercentage > tHorizPercentage then
setKeyboardScale(tHorizPercentage)
else
setKeyboardScale(tVertPercentage)
end if
put ( the right of tRect - the right of tKeyboardRect * mVertScale ) /2 into mXOffset
put ( the bottom of tRect - the bottom of tKeyboardRect * mHorizScale ) /2 into mYOffset
-- log [mXOffset, mYOffset]
--- setKeyboardScale(tPercentage)
redraw all
end handler
public handler getKeyboardScale() returns Number
return mHorizScale -- , mVertScale
end handler
/**
*/
property keyboardType get getKeyboardType set setKeyboardType
metadata keyboardType.editor is "com.livecode.pi.enum"
metadata keyboardType.label is "Keyboard Style"
metadata keyboardType.default is "full-keyboard+numpad"
metadata keyboardType.options is "full-keyboard,mini-keyboard,full-keyboard+numpad"
private variable mKeyboardType as String
public handler getKeyboardType() returns String
-- log mKeyboardType
return mKeyboardType
end handler
public handler setKeyboardType(in pKBType as String)
variable tArray as Array
-- log pKBType
if pKBType is "mini-keyboard" then
put element 1 of mKeyboardFrames into tArray
put tArray["framepath"] into mBorderPath
else if pKBType is "full-keyboard" then
put element 2 of mKeyboardFrames into tArray
put tArray["framepath"] into mBorderPath
else -- default full-keyboard+numpad
put element 3 of mKeyboardFrames into tArray
put tArray["framepath"] into mBorderPath
end if
put pKBType into mKeyboardType
buildKeyboard()
OnGeometryChanged()
redraw all
end handler
/**
Syntax:
set the vKeysDown of <widget> to <pKeyCodesList>
get the vKeysDown of <widget>
Summary: a comma seperated list of character key codes of the highlighted keys of the virtual keyboard
Description:
Use the <keysDown> property to get or set the highlighted keys of the virtual keyboard by
passing a comma delimited list of keyCodes, the same way returned from the engines keysDown()
function and as passed by rawKeyDown and rawKeyUp event messages.
*/
property vKeysDown get getKeysDown set setKeysDown
metadata vKeysDown.editor is "com.livecode.pi.string"
metadata vKeysDown.label is "Virtual keysDown"
metadata vKeysDown.default is ""
private variable mVKeysDown
public handler setKeysDown(in pKeysDown as String) returns nothing
variable tList as List
variable tKeyCode as String
variable tCounter as Number
variable tArray as Array
clearAllHighlights() -- always clear all highlights first rather than adding highlighted keys
if pKeysDown is "" or pKeysDown is "empty" then
-- clearAllHighlights()
return
else
replace "\n" with "return" in pKeysDown
replace "\t" with "tab" in pKeysDown
split pKeysDown by "," into tList
repeat for each element tKeyCode in tList
repeat with tCounter from 1 up to (the number of elements in mModifierBtns )
put element tCounter of mModifierBtns into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mModifierBtns[tCounter]
end if
end repeat
repeat with tCounter from 1 up to (the number of elements in mKeyboardBtns )
put element tCounter of mKeyboardBtns into tArray
-- log [ tArray["name"]]
if tArray["charcode"] is tKeyCode or tArray["shiftcharcode"] is tKeyCode or tArray["optcharcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mKeyboardBtns[tCounter]
end if
end repeat
repeat with tCounter from 1 up to 13
put element tCounter of mFunctionKeys into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mFunctionKeys[tCounter]
end if
end repeat
if mKeyboardType is not "mini-keyboard" then
--------
repeat with tCounter from 14 up to 16
put element tCounter of mFunctionKeys into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mFunctionKeys[tCounter]
end if
end repeat
repeat with tCounter from 1 up to 4
put element tCounter of mArrowKeys into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mArrowKeys[tCounter]
end if
end repeat
repeat with tCounter from 1 up to (the number of elements in mPageKeys )
put element tCounter of mPageKeys into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mPageKeys[tCounter]
end if
end repeat
if mKeyboardType is "full-keyboard+numpad" then
repeat with tCounter from 1 up to (the number of elements in mNumPadKeys )
put element tCounter of mNumPadKeys into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mNumPadKeys[tCounter]
end if
end repeat
---- MEDIA KEYS / F16-F19
repeat with tCounter from 1 up to (the number of elements in mMediaKeys )
put element tCounter of mMediaKeys into tArray
if tArray["charcode"] is tKeyCode then
put true into tArray["highlighted"]
put tArray into mMediaKeys[tCounter]
end if
end repeat
end if
end if
--------
end repeat
put pKeysDown into mVKeysDown
end if
redraw all
end handler
public handler getKeysDown() returns String
variable tArray as Array
variable tList as List
variable tCodes as String
put the empty string into tCodes
repeat for each element tArray in mModifierBtns
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
repeat for each element tArray in mKeyboardBtns
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
repeat for each element tArray in mFunctionKeys
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
if mKeyboardType is not "mini-keyboard" then
------
repeat for each element tArray in mArrowKeys
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
repeat for each element tArray in mPageKeys
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
if mKeyboardType is "full-keyboard+numpad" then
repeat for each element tArray in mNumPadKeys
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
--- F16 to F19 / mMediaKeys
repeat for each element tArray in mMediaKeys
if tArray["highlighted"] then
put tArray["charcode"] & "," after tCodes
end if
end repeat
end if
------
end if
if tCodes is not the empty string then
if the last char of tCodes is "," then
delete the last char of tCodes
end if
end if
put tCodes into mVKeysDown
return tCodes
end handler
public handler clearKeyHighlight(in pKeyName as String)
variable tCounter as Number
variable tArray as Array
repeat with tCounter from 1 up to (the number of elements in mModifierBtns )
put element tCounter of mModifierBtns into tArray
if tArray["name"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mModifierBtns[tCounter]
exit repeat
end if
end repeat
repeat with tCounter from 1 up to (the number of elements in mKeyboardBtns )
put element tCounter of mKeyboardBtns into tArray
if tArray["name"] is pKeyName or tArray["shiftname"] is pKeyName or tArray["optname"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mKeyboardBtns[tCounter]
exit repeat
end if
end repeat
repeat with tCounter from 1 up to (the number of elements in mFunctionKeys)
put element tCounter of mFunctionKeys into tArray
if tArray["name"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mFunctionKeys[tCounter]
exit repeat
end if
end repeat
if mKeyboardType is not "mini-keyboard" then
repeat with tCounter from 1 up to 4
put element tCounter of mArrowKeys into tArray
if tArray["name"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mArrowKeys[tCounter]
exit repeat
end if
end repeat
repeat with tCounter from 1 up to 6
put element tCounter of mPageKeys into tArray
if tArray["name"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mPageKeys[tCounter]
exit repeat
end if
end repeat
if mKeyboardType is "full-keyboard+numpad" then
repeat with tCounter from 1 up to (the number of elements in mNumPadKeys )
put element tCounter of mNumPadKeys into tArray
if tArray["name"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mNumPadKeys[tCounter]
exit repeat
end if
end repeat
repeat with tCounter from 1 up to 4
put element tCounter of mMediaKeys into tArray
if tArray["name"] is pKeyName then
put false into tArray["highlighted"]
put tArray into mMediaKeys[tCounter]
exit repeat
end if
end repeat
end if
end if
-- getKeysDown() -- update the VkeysDown string
redraw all
end handler
private handler clearAllHighlights()
variable tCounter as Number
variable tArray as Array
repeat with tCounter from 1 up to (the number of elements in mModifierBtns )
put element tCounter of mModifierBtns into tArray
put false into tArray["highlighted"]
put tArray into mModifierBtns[tCounter]
end repeat
repeat with tCounter from 1 up to (the number of elements in mKeyboardBtns )
put element tCounter of mKeyboardBtns into tArray
put false into tArray["highlighted"]
put tArray into mKeyboardBtns[tCounter]
end repeat
repeat with tCounter from 1 up to (the number of elements in mFunctionKeys )
put element tCounter of mFunctionKeys into tArray
put false into tArray["highlighted"]
put tArray into mFunctionKeys[tCounter]
end repeat
if mKeyboardType is not "mini-keyboard" then
repeat with tCounter from 1 up to 4
put element tCounter of mArrowKeys into tArray
put false into tArray["highlighted"]
put tArray into mArrowKeys[tCounter]
end repeat
repeat with tCounter from 1 up to (the number of elements in mPageKeys )
put element tCounter of mPageKeys into tArray
put false into tArray["highlighted"]
put tArray into mPageKeys[tCounter]
end repeat
if mKeyboardType is "full-keyboard+numpad" then
repeat with tCounter from 1 up to (the number of elements in mNumPadKeys )
put element tCounter of mNumPadKeys into tArray
put false into tArray["highlighted"]
put tArray into mNumPadKeys[tCounter]
end repeat
repeat with tCounter from 1 up to (the number of elements in mMediaKeys )
put element tCounter of mNumPadKeys into tArray
put false into tArray["highlighted"]
put tArray into mMediaKeys[tCounter]
end repeat
end if
end if
put "" into mVKeysDown
redraw all
end handler
-------------------------------------------------------- this handler is called when the widget is saved
public handler OnSave(out rProperties as Array)
put the empty array into rProperties
put colorToString(mColor, true) into rProperties["foregroundColor"]
put colorToString(mBackColor, true) into rProperties["backgroundColor"]
put colorToString(mStrokeColor, true) into rProperties["borderColor"]
put colorToString(mHiliteColor, true) into rProperties["hiliteColor"]
put mToggleMediaKeys into rProperties["toggle mediakeys"]
put mToggleAntiAlias into rProperties["toggle antialias"]
put mToggleLEDs into rProperties["toggle LEDs"]
put mOpaque into rProperties["opaque"]
put mHorizScale into rProperties["horizScale"]
put mVertScale into rProperties["vertScale"]
put mStrokeWidth into rProperties["Stroke width"]
put mMaintainAspectRatio into rProperties["maintain aspect ratio"]
put mVKeysDown into rProperties["virtualKeysDown"]
put mKeyboardType into rProperties["keyboardType"]
return rProperties
end handler
-------------------------------------------------------- this handler is called when the widget is loaded
public handler OnLoad(in pProperties as Array)
put stringToColor(pProperties["foregroundColor"]) into mColor
put stringToColor(pProperties["backgroundColor"]) into mBackColor
put stringToColor(pProperties["borderColor"]) into mStrokeColor
put stringToColor(pProperties["hiliteColor"]) into mHiliteColor
put pProperties["toggle mediakeys"] into mToggleMediaKeys
put pProperties["toggle antialias"] into mToggleAntiAlias
put pProperties["toggle LEDs"] into mToggleLEDs
put pProperties["opaque"] into mOpaque
put pProperties["horizScale"] into mHorizScale
put pProperties["vertScale"] into mVertScale
put pProperties["Stroke width"] into mStrokeWidth
put pProperties["maintain aspect ratio"] into mMaintainAspectRatio
put pProperties["virtualKeysDown"] into mVKeysDown
put pProperties["keyboardType"] into mKeyboardType
end handler
------------------------------------------------ the following handlers deal with mouse and keyboard events --------
private variable mMouseDown as optional Boolean
private variable mPrevMouseH as optional Number
private variable mPrevMouseV as optional Number
private variable mLastSelectedPath as optional Path
private variable mPreviousKey as optional String
public handler OnMouseMove()
variable tPath -- as Path
variable tArray as Array
variable tElementNum as Number
-- checkModifiers()
variable tMouseH as Number
variable tMouseV as Number
------------------------------------ Here's 2 ways to get the mousePosition ---------------
----------------------- the Scripting Engine Way: -----------------------
-- variable tMouseLoc as List
--execute script "return mouseLoc()"
--split the result by "," into tMouseLoc
--parse tMouseLoc as list of number into tMouseLoc
--put tMouseLoc[1] into tMouseH
--put tMouseLoc[2] into tMouseV
----------------------- the Extension Builder Way: -----------------------
put the x of the mouse position / my pixel scale into tMouseH
put the y of the mouse position / my pixel scale into tMouseV
----/----------------------------------------------------------------------
-- if tMouseH <> mPrevMouseH or tMouseV <> mPrevMouseV then ------------------------ do check for within key rects here
-- log [tMouseH,tMouseV]
--------------------------------
--- if the current mouse position is within my bounds then
if mMouseDown is not nothing and mMouseDown is true then
if mToggleVKeyUp is false then
if (the mouse position is not within the bounding box of mLastSelectedPath) then
if mPreviousKey is not nothing and mPreviousKey is not "" then
clearKeyHighlight(mPreviousKey)
post "virtualKeyUp" with [mPreviousKey]
put "" into mPreviousKey
put the empty path into mLastSelectedPath
end if
end if
repeat with tElementNum from 1 up to (the number of elements in mModifierBtns) ----------------- Modifier Keys
put mModifierBtns[tElementNum] into tArray
put path (tArray["btnpath"]) into tPath
scale tPath by [mHorizScale,mVertScale]
translate tPath by [mXOffset,mYOffset]
if (the mouse position is within the bounding box of tPath) then
put true into tArray["highlighted"]
put tArray into element tElementNum of mModifierBtns
post "virtualKeyDown" with [tArray["name"]]
put tArray["name"] into mPreviousKey
put tPath into mLastSelectedPath
exit repeat
end if
end repeat
repeat with tElementNum from 1 up to (the number of elements in mKeyboardBtns) --------- Main Keys
put mKeyboardBtns[tElementNum] into tArray
put path (tArray["btnpath"]) into tPath
scale tPath by [mHorizScale,mVertScale]
translate tPath by [mXOffset,mYOffset]
if (the mouse position is within the bounding box of tPath) then
put true into tArray["highlighted"]
put tArray into element tElementNum of mKeyboardBtns
if the shift key is currently down then
post "virtualKeyDown" with [tArray["shiftname"]]
put tArray["shiftname"] into mPreviousKey
else if the option key is currently down then
post "virtualKeyDown" with [tArray["optname"]]
put tArray["optname"] into mPreviousKey
else
post "virtualKeyDown" with [tArray["name"]]
put tArray["name"] into mPreviousKey
end if
put tPath into mLastSelectedPath
exit repeat
end if
end repeat