-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasetniop.js
1822 lines (1545 loc) · 55.8 KB
/
asetniop.js
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
//Version 1.2.0
//added simple predictive
/*DIFFERENCES BETWEEN ANDRIOD/JAVA VERSION
JS will suggest all caps words as predictive regardless of shift state (but will suggest them in shifted form), A/J will only suggest them if first letter is capitalized (and uses a different threshold)
*/
//create master asetniop object to contain program states
asetniop = {}
settings = {}
//settings for determining initial output
settings.word_bonus = 100
settings.left_bonus = 4 //whether other formulation will supersede
settings.right_bonus = 4 //whether other formulation will supersede
settings.one_group_cutoff = 0.001 //if one-letter words do not occur with this frequency, it checks for autocorrect
settings.backspace_interval = [125,67,32,16]
settings.backspace_hold = [4,15,30,100]
settings.word_autocorrect_status = true //on/off switch for autocorrect; if FALSE it is always off.
settings.num_autocorrect_status = false //autcorrect always off for numbers and symbols
settings.autocorrect_status = settings.word_autocorrect_status
settings.predictive = true //on/off switch for predictive - current cannot be turned off because feeds into accent_inline functionality
settings.predictive_length = 1 //CANNOT BE LESS THAN 1
settings.predictive_factor = 3 //if top choice is this many times more common than second choice, will suggest
settings.accent_inline = true; //starts off true, can be toggled via the index page
settings.num_predictions = 5
settings.layout = "standard"
//init()
//ADD 'STATS' TO DICTIONARY
//FIND TOUCH-END KEYS TO PREVENT STUCK KEYS...still an issue
//RESOLVE LOST SPACES - SOMETIMES SPACE HITS DON'T REGISTER - think it's because if too many keys are down it won't register the space
function visual_key_down(active_button){
$("#b_"+active_button).addClass("down_button")
}
function visual_key_up(active_button){
$("#b_"+active_button).removeClass("down_button")
}
function visual_iterate_shift(active_button, new_shift_state){
if(new_shift_state == 0){
$("#b_"+active_button).removeClass("down_button")
$("#b_"+active_button).removeClass("caps_button")
}
else if(new_shift_state == 1){
$("#b_"+active_button).addClass("down_button")
}
else if(new_shift_state == 2){
$("#b_"+active_button).removeClass("down_button")
$("#b_"+active_button).addClass("caps_button")
}
}
function visual_add_keystroke(keystroke){
output_string = $("#output_text").text()
if(keystroke == 'backspace'){
output_string = output_string.substring(0,output_string.length - 1)
}
else if(keystroke == 'enter'){
output_string += "\n"
}
else{
output_string += keystroke
}
$("#output_text").text(output_string)
additional_processing();
}
function additional_processing(){
//currently does nothing; can be superseded (in html page or elsewhere) if needed
}
function visual_update_cursor(predictive, word){
if(!predictive){
if(asetniop.cursor_state == 'letters'){
$("#cursor").text("_")
}
else if(asetniop.cursor_state == 'numsym'){
$("#cursor").text("#")
}
}
else{
word_diff = word.length - asetniop.current_word.length
suffix = word.substring(word.length - word_diff,word.length)
$("#cursor").text(suffix)
}
}
function visual_update_prediction(reset, choice_array){
for(i = 0; i < settings.num_predictions; i++){
$("#prediction_"+i).removeClass("predictive_highlight")
}
if(reset){
for(i = 0; i < settings.num_predictions; i++){
$("#prediction_"+i).text("")
}
}
else{
for(i = 0; i < choice_array.length; i++){
$("#prediction_"+i).text(choice_array[i])
}
}
}
function visual_iterate_prediction(iteration){
for(i = 0; i < settings.num_predictions; i++){
$("#prediction_"+i).removeClass("predictive_highlight")
}
$("#prediction_"+asetniop.prediction_iteration).addClass("predictive_highlight")
}
function visual_display_keyboard(){
//keyboard remains invisible until dictionary has finished loading
$("#container").css("display", "block");
}
function visual_clear_text(){
$("#output_text").text("")
additional_processing()
initial_states()
reset_word_states()
reset_key_states()
visual_update_prediction(true)
}
function visual_update_labels(){
if(settings.layout == "colemak"){
base = ["A","R","S","T","N","E","I","O"]
subbase = ["Q (","W Z","X F","P C D B V G","J K M H L",", U",". - Y","← ) ' ? ! ;"]
numbase = ["1","2","3","4","7","8","9","0"]
numsubbase = ["` \ (","• £","×","{ 5 =","6 }","π ,",". - €","? ) ' ← ! ;"]
backspace_code = 129
}
else if(settings.layout == "dvorak"){
base = ["A","O","E","I","H","T","N","S"]
subbase = ["! ; ( '",", Q",". J","P Y U K X","B F D G M","W C","V R","- ← ) ? Z L"]
numbase = ["1","2","3","4","7","8","9","0"]
numsubbase = ["` \ (","• £","×","{ 5 =","6 }","π ,",". - €","? ) ' ← ! ;"]
backspace_code = 130
}
else{
base = ["A","S","E","T","N","I","O","P"]
subbase = ["Q Z (","W C","X D","F R B V G","J Y H U M","K ,",". - L","? ) ' ← ! ;"]
numbase = ["1","2","3","4","7","8","9","0"]
numsubbase = ["` \ (","• £","×","{ 5 =","6 }","π ,",". - €","? ) ' ← ! ;"]
backspace_code = 136
}
if(asetniop.num_keys_down == 0){
if(asetniop.cursor_state == 'numsym')
{
for(i = 0; i < 8; i++){
$("#label_"+i).html(numbase[i])
$("#sublabel_"+i).html(numsubbase[i])
}
}
else{
for(i = 0; i < 8; i++){
$("#label_"+i).html(base[i])
$("#sublabel_"+i).html(subbase[i])
}
}
}
else if(asetniop.num_keys_down == 1){
if (asetniop.max_num_keys_down == 1) {
for(i = 0; i < 8; i++){
calc_state = Math.pow(2, i);
if (calc_state == asetniop.key_state) {
//leave current label alone
} else {
if(calc_state + asetniop.key_state == backspace_code){
output = "←"
}
else{
if (asetniop.shift == 1) {
output = asetniop.active_keymap[calc_state + asetniop.key_state].baseshift
} else {
output = asetniop.active_keymap[calc_state + asetniop.key_state].base.toUpperCase()
}
}
$("#label_"+i).html(output)
$("#sublabel_"+i).html("")
}
}
} else {
//leaves them alone
}
}
else if(asetniop.num_keys_down == 2){
if (asetniop.max_num_keys_down == 2) {
for(i = 0; i < 8; i++){
if (asetniop.pressed_buttons[i]) {
if(asetniop.key_state == backspace_code){
output = "←"
}
else{
if (asetniop.shift == 1) {
output = asetniop.active_keymap[asetniop.key_state].baseshift
} else {
output = asetniop.active_keymap[asetniop.key_state].base.toUpperCase()
//don't forget to update keymaps to include ↠arrow key for backspace.base.
}
}
$("#label_"+i).html(output)
} else {
$("#label_"+i).html("")
}
}
} else {
//leaves them alone
}
}
}
function initial_states(){ //only ones not covered by resets
asetniop.shift = 0 //initial state; off
visual_iterate_shift(8,0) //ensure shift key is not lit up
asetniop.shift_no_reset = false;
asetniop.backspace_repeat = 0;
asetniop.backspace_interval = settings.backspace_interval[0]
asetniop.cursor_state = 'letters'
}
function reset_word_states(){
asetniop.current_word = ""
asetniop.key_groups = []
asetniop.text_groups = []
asetniop.shift_status = []
asetniop.autocorrect_state = settings.autocorrect_status
asetniop.predictive = false
asetniop.skip_predictive_iteration = true
asetniop.prediction_iteration = -1;
asetniop.num_active_predictions = 0;
asetniop.basechoicearray = []
}
function reset_key_states(){
asetniop.key_state = 0
asetniop.max_key_state = 0
asetniop.num_keys_down = 0
asetniop.max_num_keys_down = 0
asetniop.leading_space = false
asetniop.trailing_space = false
asetniop.key_sequence = []
asetniop.pressed_buttons = []
for(var i=0; i<10; i++){
asetniop.pressed_buttons[i] = false
}
asetniop.backspace_first_time = true
asetniop.backspace_counter = 0
asetniop.autocorrect_tripped = false
//scrolling behavior
$(document).scrollTop($(document).height());
}
function reset_shift(){
//only resets if shift has been released
if(asetniop.predictive && !asetniop.keys_down[8] && !asetniop.skip_predictive_iteration){
advance_prediction_iteration()
visual_iterate_prediction()
}
if(!asetniop.keys_down[8] && asetniop.shift_no_reset){
asetniop.shift = 0
visual_iterate_shift(8,0)
asetniop.shift_no_reset = false
}
}
function iterate_shift(){
if(asetniop.predictive && asetniop.predictive_output.length > 0){ //if predictive is on AND contains choices
if(asetniop.keys_down[8] && asetniop.shift != 1){
if(asetniop.shift == 0){
asetniop.shift = 1
visual_iterate_shift(8,1)
asetniop.shift_no_reset = true
asetniop.skip_predictive_iteration = false
}
if(asetniop.shift == 2){
asetniop.shift_no_reset = false
asetniop.skip_predictive_iteration = false
}
}
}
else{
asetniop.shift_no_reset = false
if(asetniop.shift == 0){
asetniop.shift = 1
visual_iterate_shift(8,1)
}
else if(asetniop.shift == 1){
asetniop.shift = 2
visual_iterate_shift(8,2)
}
else if(asetniop.shift == 2){
//if CAPS is down and user tried to hold and shift punctuation, (say, >) shift will iterate instead. Maybe add separate action for key release?
asetniop.shift = 0
visual_iterate_shift(8,0)
}
}
}
function backspace_actions(){
//reset shift if in basic shift mode
if(asetniop.shift == 1){
asetniop.shift_no_reset = true
reset_shift()
}
//generate new predictions
if(asetniop.current_word.length > 0){
asetniop.shift_status.pop()
if(!asetniop.autocorrect_tripped){
asetniop.current_word = asetniop.current_word.substring(0,asetniop.current_word.length - 1)
}
//keep key_groups and text_groups clean
asetniop.key_groups.pop()
asetniop.text_groups.pop()
}
predictive_generation(1)
}
function advance_prediction_iteration(){
asetniop.prediction_iteration += 1
if(asetniop.prediction_iteration >= asetniop.num_active_predictions){
asetniop.prediction_iteration = -1
}
if(asetniop.prediction_iteration >= 0 && asetniop.current_word.length == asetniop.predictive_base[asetniop.prediction_iteration].length && settings.accent_inline){
accent_replace(asetniop.predictive_output[asetniop.prediction_iteration], asetniop.predictive_base[asetniop.prediction_iteration])
}else{
accent_replace(asetniop.current_word, asetniop.current_word)
}
}
function accent_replace(word, base){
//trim original
output_string = $("#output_text").text()
output_string = output_string.substring(0,output_string.length - base.length);
$("#output_text").text(output_string)
//update output
for(var i=0; i<word.length; i++){
visual_add_keystroke(word[i])
}
}
//INTERFACE FUNCTIONS - VARIOUS FUNCTIONS THAT CONNECT FRONT-END INTERACTIONS (KEYBOARD PRESSES, TOUCHSCREEN TOUCHES, ETC.) TO BACK-END PROCESSING
//use these functions when keyboard keys are pressed, then send action to button_down and button_up functions
function keydown(event){
event.preventDefault()
//reference keycode to key
if(event.keyCode == 8){
button_down(3);
button_down(7);
}
else{
//console.log(event.keyCode)
if(asetniop.active_keycodes[event.keyCode] != undefined){
active_button = asetniop.active_keycodes[event.keyCode][1]
button_down(active_button)
}
else{
console.log("inactive key")
}
}
}
function keyup(event){
event.preventDefault()
//reference keycode to key
if(event.keyCode == 8){
button_up(3);
button_up(7);
}
else if(asetniop.active_keycodes[event.keyCode] != undefined){
active_button = asetniop.active_keycodes[event.keyCode][1]
button_up(active_button)
}
}
function init(){
//bind touch functions to overlay elements
$('#o_0').on({ 'touchstart' : function(){ button_down(0) } });
$('#o_0').on({ 'touchend' : function(){ button_up(0) } });
$('#o_0').on({ 'touchcancel' : function(){ button_up(0) } });
$('#o_1').on({ 'touchstart' : function(){ button_down(1) } });
$('#o_1').on({ 'touchend' : function(){ button_up(1) } });
$('#o_1').on({ 'touchcancel' : function(){ button_up(1) } });
$('#o_2').on({ 'touchstart' : function(){ button_down(2) } });
$('#o_2').on({ 'touchend' : function(){ button_up(2) } });
$('#o_2').on({ 'touchcancel' : function(){ button_up(2) } });
$('#o_3').on({ 'touchstart' : function(){ button_down(3) } });
$('#o_3').on({ 'touchend' : function(){ button_up(3) } });
$('#o_3').on({ 'touchcancel' : function(){ button_up(3) } });
$('#o_4').on({ 'touchstart' : function(){ button_down(4) } });
$('#o_4').on({ 'touchend' : function(){ button_up(4) } });
$('#o_4').on({ 'touchcancel' : function(){ button_up(4) } });
$('#o_5').on({ 'touchstart' : function(){ button_down(5) } });
$('#o_5').on({ 'touchend' : function(){ button_up(5) } });
$('#o_5').on({ 'touchcancel' : function(){ button_up(5) } });
$('#o_6').on({ 'touchstart' : function(){ button_down(6) } });
$('#o_6').on({ 'touchend' : function(){ button_up(6) } });
$('#o_6').on({ 'touchcancel' : function(){ button_up(6) } });
$('#o_7').on({ 'touchstart' : function(){ button_down(7) } });
$('#o_7').on({ 'touchend' : function(){ button_up(7) } });
$('#o_7').on({ 'touchcancel' : function(){ button_up(7) } });
$('#o_8').on({ 'touchstart' : function(){ button_down(8) } });
$('#o_8').on({ 'touchend' : function(){ button_up(8) } });
$('#o_8').on({ 'touchcancel' : function(){ button_up(8) } });
$('#o_9').on({ 'touchstart' : function(){ button_down(9) } });
$('#o_9').on({ 'touchend' : function(){ button_up(9) } });
$('#o_9').on({ 'touchcancel' : function(){ button_up(9) } });
/*
mouse versions
$("#b_0").mousedown(function() {button_down(0)});
$("#b_0").mouseup(function() {button_up(0)});
$("#b_0").mouseout(function() {button_up(0)});
*/
asetniop.keys_down = {}
for(var i=0; i<10; i++){
asetniop.keys_down[i] = false
}
initial_states()
reset_word_states()
reset_key_states()
load_new_language()
}
function load_new_language(){
language = $('#language_select').val()
full_language = language;
if(language.indexOf("colemak") > -1){
language = language.substring(0,2)
settings.layout = "colemak"
}
else if(language.indexOf("dvorak") > -1){
language = language.substring(0,2)
settings.layout = "dvorak"
}
else{
settings.layout = "standard"
}
//load settings file
$.getJSON("../resources/settings/settings_arrays.json", function(data){
asetniop.settings = data
//set up initial settings
asetniop.active_keycodes = asetniop.settings.keycodes.QWERTY
if(settings.layout == "colemak"){
asetniop.active_keycodes = asetniop.settings.keycodes.Colemak
}
else if(settings.layout == "dvorak"){
asetniop.active_keycodes = asetniop.settings.keycodes.Dvorak
}
else{
//already good
}
})
$.getJSON("../resources/keymaps/" + full_language + "-keymap.json", function(data){
asetniop.keymap = data
//sets active_keymap to letters
asetniop.active_keymap = asetniop.keymap
})
$.getJSON("../resources/keymaps/num-keymap.json", function(data){
asetniop.numkeymap = data
})
//load dictionary and predictive objects
$.getJSON("../resources/dictionaries/" + language + "-initial.json", function(data){
asetniop.totalwordcount = data.dictionarystats.totalwordcount
})
$.getJSON("../resources/dictionaries/" + language + "-snap.json", function(data){
asetniop.snapdic = data
})
$.getJSON("../resources/dictionaries/" + language + "-dictionary.json", function(data){
asetniop.prioritydic = data.prioritydic
//add "asetniop" to dictionary
add_word_to_prioritydic("asetniop", 100)
visual_display_keyboard()
})
visual_update_labels()
}
function add_word_to_prioritydic(word, count){
letterarray = word.split("");
numletters = letterarray.length;
evalexpression = 'asetniop.prioritydic';
for(y = 0; y < numletters; y++){
evalexpression = evalexpression + '.' + letterarray[y];
//breaks loop if it finds a mistake
if(!eval(evalexpression)){
eval(evalexpression + " = {}")
}
}
eval(evalexpression + ".nn = " + count)
}
function button_down(active_button){
//activate key
if(!asetniop.keys_down[active_button]){
asetniop.keys_down[active_button] = true
if(active_button <= 7){
//add keypress to tracked sequence for autocorrect
if(!asetniop.pressed_buttons[active_button]){
asetniop.key_sequence.push(active_button)
asetniop.max_key_state += Math.pow(2,active_button);
asetniop.max_num_keys_down += 1
}
if(asetniop.max_num_keys_down == 2 && asetniop.active_keymap[asetniop.max_key_state].special == 'bksp'){
asetniop.backspace_active = true
asetniop.backspace_repeat=setInterval(backspace_repeat_function, asetniop.backspace_interval)
backspace_repeat_function();
}
else{ //make sure clearInterval stops appropriately
if(asetniop.backspace_active){
clearInterval(asetniop.backspace_repeat);
asetniop.backspace_interval = settings.backspace_interval[0]
asetniop.backspace_counter = 0
}
}
asetniop.pressed_buttons[active_button] = true
//visual elements
visual_key_down(active_button)
// original code used |= instead; think it only allows addition
asetniop.key_state += Math.pow(2,active_button);
asetniop.num_keys_down += 1
//deactivates shift hold for predictive
asetniop.skip_predictive_iteration = true
}
//special case for shift
else if(active_button == 8){
iterate_shift()
}
//special case for space
else if(active_button == 9){
visual_key_down(active_button)
if(asetniop.num_keys_down > 0){
asetniop.trailing_space = true
}
else{
asetniop.leading_space = true
}
}
}
visual_update_labels()
}
function button_up(active_button){
//deactivate key
if(asetniop.keys_down[active_button]){
asetniop.keys_down[active_button] = false
// original code used &= instead; think it allows only subtraction
if(active_button <= 7){
visual_key_up(active_button)
asetniop.key_state -= Math.pow(2,active_button);
asetniop.num_keys_down -= 1
//backspace special case
if(asetniop.num_keys_down == 1 && asetniop.active_keymap[asetniop.max_key_state].special == 'bksp'){
if(asetniop.backspace_active){
//stop repeater and reset intervals
clearInterval(asetniop.backspace_repeat);
asetniop.backspace_interval = settings.backspace_interval[0]
}
if(asetniop.backspace_counter <= settings.backspace_hold[0]){
//need to prevent extra backspace on release when repeater is active
if(asetniop.backspace_first_time){
//run autocorrect check for potential t/p and p/t words
backspace_fix = backspace_autocorrect(asetniop.current_word)
if(backspace_fix[0]){
processed_output = backspace_fix[1]
processed_shift = backspace_fix[2]
for(var i=0; i<processed_output.length; i++){
processed_letter = processed_output[i]
visual_add_keystroke(processed_letter)
//update trackers
asetniop.current_word += processed_letter
asetniop.text_groups.push(processed_letter)
asetniop.key_groups.push([asetniop.key_sequence[i]])
asetniop.shift_status.push(processed_shift[i])
}
}
else{
asetniop.backspace_first_time = false
asetniop.autocorrect_state = false
backspace_actions()
visual_add_keystroke('backspace')
}
}
else{
backspace_actions()
visual_add_keystroke('backspace')
}
}
asetniop.backspace_counter = 0
}
asetniop.backspace_active = false
}
//special cases for space and shift
if(active_button == 9){
visual_key_up(active_button)
}
if(active_button == 8){
reset_shift()
}
if(asetniop.key_state == 0){
//process key
process_output()
reset_key_states()
}
}
visual_update_labels()
}
function backspace_repeat_function(){
if(asetniop.backspace_counter > settings.backspace_hold[0]){
backspace_actions()
visual_add_keystroke('backspace')
}
asetniop.backspace_counter += 1
//run through various tiers to see if time to accelerate
for(var i=1; i<settings.backspace_hold.length; i++){
if(asetniop.backspace_counter == settings.backspace_hold[i]){
asetniop.backspace_interval = settings.backspace_interval[i]
//kill old repeater and restart with new interval
clearInterval(asetniop.backspace_repeat);
asetniop.backspace_repeat=setInterval(backspace_repeat_function, asetniop.backspace_interval)
backspace_repeat_function();
}
}
}
function process_output(){
//deal with special cases (backspace, etc.)
if(asetniop.active_keymap[asetniop.max_key_state].special){
if(asetniop.active_keymap[asetniop.max_key_state].special == 'bksp'){
//has already processed
return true
}
if(asetniop.active_keymap[asetniop.max_key_state].special == 'enter'){
visual_add_keystroke('enter')
reset_key_states()
reset_word_states()
visual_update_prediction(true)
return true
}
else if(asetniop.active_keymap[asetniop.max_key_state].special == 'numsym'){
asetniop.active_keymap = asetniop.numkeymap
settings.autocorrect_status = settings.num_autocorrect_status
asetniop.autocorrect_state = false
asetniop.cursor_state = 'numsym'
visual_update_cursor(false)
return true
}
else if(asetniop.active_keymap[asetniop.max_key_state].special == 'letters'){
asetniop.active_keymap = asetniop.keymap
settings.autocorrect_status = settings.word_autocorrect_status
asetniop.autocorrect_state = false
asetniop.cursor_state = 'letters'
visual_update_cursor(false)
return true
}
}
backtrack = 0 //how far back it will reach
original_output = ""
processed_output = ""
alpha_output = ""
if(asetniop.leading_space){
//close off previous word and check autocorrect
if(asetniop.autocorrect_state && asetniop.prediction_iteration < 0){
replacement = word_autocorrect(asetniop.current_word)
if(replacement[0]){
processed_output += replacement[1]
backtrack += replacement[1].length + (asetniop.current_word.length - replacement[1].length)
}
}
original_output += " "
processed_output += " "
backtrack += 0
//actuate prediction, if appropriate
if(processed_output == " " && asetniop.predictive == true && asetniop.shift == 1){
advance_prediction_iteration()
visual_iterate_prediction()
actuate_prediction(0)
backtrack = 0
}
else if(processed_output == " " && asetniop.predictive == true && asetniop.prediction_iteration > -1){
actuate_prediction(0)
backtrack = 0
}
reset_word_states()
}
if(asetniop.max_key_state > 0){
output_object = asetniop.active_keymap[asetniop.max_key_state]
//record shift status
asetniop.shift_no_reset = true
if(asetniop.max_num_keys_down < 3){
if(asetniop.shift == 0){ // regular
alpha_output = output_object.base
}
else if(asetniop.shift == 1){ // shift OR shift key currently being held down
alpha_output = output_object.baseshift
//reset_shift()
}
else if(asetniop.shift == 2){ // caps lock - ignores punctuation
if(asetniop.keys_down[8]){ //if shift is currently being held down
//shift output and prevent caps lock from turning off
asetniop.shift_no_reset = false
if("!(?).,-;'1234567890".indexOf(output_object.base) > -1){
alpha_output = output_object.baseshift
}
else{
alpha_output = output_object.base
}
}
else{
if("!(?).,-;'1234567890".indexOf(output_object.base) > -1){
alpha_output = output_object.base
}
else{
alpha_output = output_object.baseshift
}
}
}
}
else{
//figure out first/base choice
for(var i=0; i<asetniop.key_sequence.length; i++){
alpha_output += asetniop.active_keymap[binary_calculator([asetniop.key_sequence[i]])].base // base output only used if there is NOTHING else
}
//determine bonuses
word_bonus = 1
left_bonus = 1
right_bonus = 1
//supersede with more practical option, if available
if(asetniop.key_sequence[0] < 4){
left_bonus = settings.left_bonus
if(asetniop.trailing_space && asetniop.current_word == "" && output_object.tlw){ //pure word
word_bonus = settings.word_bonus
alpha_output = output_object.tlw[0]
}
else if(output_object.tlp){
alpha_output = output_object.tlp[0]
}
}
else if(asetniop.key_sequence[0] >= 4){
right_bonus = settings.right_bonus
if(asetniop.trailing_space && asetniop.current_word == "" && output_object.trw){ //pure word
word_bonus = settings.word_bonus
alpha_output = output_object.trw[0]
}
else if(output_object.trp){
alpha_output = output_object.trp[0]
}
}
// if possible make smarter decision about what to use
beta_array = []
//push objects into beta_array after adjusting counts based on keyboard state - won't consider ones that don't make sense as words
if(output_object.tlp && wordcheck(asetniop.current_word + output_object.tlp[0], true)){
beta_array.push([output_object.tlp[0],output_object.tlp[1]*left_bonus])
}
if(output_object.trp && wordcheck(asetniop.current_word + output_object.trp[0], true)){
beta_array.push([output_object.trp[0],output_object.trp[1]*right_bonus])
}
if(output_object.tlw && wordcheck(asetniop.current_word + output_object.tlw[0], true)){
beta_array.push([output_object.tlw[0],output_object.tlw[1]*left_bonus*word_bonus])
}
if(output_object.trw && wordcheck(asetniop.current_word + output_object.trw[0], true)){
beta_array.push([output_object.trw[0],output_object.trw[1]*right_bonus*word_bonus])
}
if(beta_array.length > 0){
beta_array = beta_array.sort(function(x,y) { return y[1] - x[1] });
alpha_output = beta_array[0][0]
}
//update shift status and apply appropriate shift response
if(asetniop.shift == 1){ // capitalize first letter
alpha_output = alpha_output.charAt(0).toUpperCase() + alpha_output.slice(1);
//reset_shift()
}
else if(asetniop.shift == 2){ // caps lock - uppercase all except punctuation/hyphens etc.
alpha_output = alpha_output.toUpperCase();
}
}
asetniop.current_word += alpha_output
//update shift status and reset
for(var i=0; i<alpha_output.length; i++){
if(asetniop.shift == 2){
asetniop.shift_status.push(2)
}
else if(i == 0 && asetniop.shift == 1){
asetniop.shift_status.push(1)
reset_shift()
}
else{
asetniop.shift_status.push(0)
}
}
original_output += alpha_output
processed_output += alpha_output
backtrack += 0
//update key history
asetniop.key_groups.push(asetniop.key_sequence)
asetniop.text_groups.push(alpha_output)
if(asetniop.autocorrect_state && !asetniop.trailing_space && asetniop.prediction_iteration < 0){ // will not process if there's a trailing space; will do word_autocorrect only
replacement = partial_autocorrect(asetniop.current_word)
if(replacement[0]){
processed_output = replacement[1]
backtrack = replacement[1].length + (asetniop.current_word.length - replacement[1].length) - original_output.length
asetniop.current_word = replacement[1]
asetniop.autocorrect_tripped = true
}
}
}
if(asetniop.trailing_space){
//close off word and run autocorrect check
if(asetniop.autocorrect_state && asetniop.prediction_iteration < 0){
replacement = word_autocorrect(asetniop.current_word)
if(replacement[0]){
//replace these with corrections
processed_output = replacement[1]
backtrack = replacement[1].length + (asetniop.current_word.length - replacement[1].length) - original_output.length
}
}
processed_output += " "
backtrack += 0
original_output += " "
if(processed_output == " " && asetniop.predictive == true){
actuate_prediction(0)
backtrack = 0
}
punctuation_string = " , < . > ? / ! | ; : ' \" - _ ( ) [ ] { } ¿ ¡ "
if(processed_output.length == 2 && punctuation_string.indexOf(processed_output) > -1 && asetniop.predictive == true && asetniop.prediction_iteration > -1){
actuate_prediction(1)
backtrack = 0
}
reset_word_states()
}
//special situations; unshift after space
if(original_output == " " && asetniop.shift == 1){
asetniop.shift_no_reset = true
reset_shift()
}
//special situation; punctuation after prediction has been selected
punctuation_string = ",<.>?/!|;:'\"-_()[]{}¿¡"
if(processed_output.length == 1 && punctuation_string.indexOf(processed_output) > -1 && asetniop.predictive == true && asetniop.prediction_iteration > -1){
actuate_prediction(1)
backtrack = 0
reset_word_states()
}
//SEND PROCESSED OUTPUT TO SCREEN
for(var i=0; i<backtrack; i++){
if(!asetniop.autocorrect_tripped){
backspace_actions()
}
visual_add_keystroke('backspace')
}
for(var i=0; i<processed_output.length; i++){
visual_add_keystroke(processed_output[i])
}
visual_update_cursor(false) //resets cursor
//GENERATE PREDICTIONS
predictive_generation(processed_output.length)
}