Skip to content

Commit 7a3e1ec

Browse files
author
jg
committed
Changing up how multikey works to better fit with built in robotjs and kbmrobot standards.
1 parent 18d1c56 commit 7a3e1ec

File tree

4 files changed

+79
-39
lines changed

4 files changed

+79
-39
lines changed

gui/index.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ <h3>Type Specific</h3>
143143
</div>
144144
</div>
145145
<div class="multi-button" style="display:none">
146-
<label class="col-form-label">Buttons to Press</label>
147-
<div class="multi-button-array">
146+
<div class="multi-button-key">
147+
<label class="col-form-label">Primary Key</label>
148148
<input class="form-control" type="text" placeholder="W" name="buttonPress" data-toggle="tooltip" data-placement="left" title="A key that will be pressed.">
149149
</div>
150+
<div class="multi-button-array">
151+
<label class="col-form-label">Modifiers</label>
152+
<input class="form-control" type="text" placeholder="shift" name="buttonPress" data-toggle="tooltip" data-placement="left" title="A modifier to press with the primary key. Accepts: control, alt, shift, or command(mac).">
153+
</div>
150154
<div class="multi-button-add-wrap">
151155
<button class="btn multi-button-add" type="button" data-toggle="tooltip" data-placement="left" title="Add another key."><i class="fa fa-plus-circle" aria-hidden="true"></i></button>
152156
<button class="btn multi-button-del" type="button" data-toggle="tooltip" data-placement="bottom" title="Delete last key."><i class="fa fa-minus-circle" aria-hidden="true"></i></button>

gui/js/form-validation.js

+19
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ function gameButtonValidation(){
135135
source: availableButtons,
136136
appendTo: ".game-button-counter"
137137
});
138+
$( ".multi-button-key input" ).autocomplete({
139+
source: availableButtons,
140+
appendTo: ".multi-button-key"
141+
});
142+
}
143+
144+
// Load up autocomplete for game buttons
145+
function gameButtonModifierValidation(){
146+
// First destory any pre-existing auto completes.
147+
148+
// This is a list of all valid buttons for bot robotjs and kbm robot.
149+
var availableButtons = [
150+
"alt",
151+
"control",
152+
"command",
153+
"shift",
154+
];
138155
$( ".multi-button-array input" ).autocomplete({
139156
source: availableButtons,
140157
appendTo: ".multi-button-array"
@@ -143,10 +160,12 @@ function gameButtonValidation(){
143160

144161
// Exports
145162
exports.gameValidate = gameButtonValidation;
163+
exports.gameModifierValidate = gameButtonModifierValidation;
146164
exports.clearValidate = clearValidate;
147165

148166
// On App Load
149167
$(document).ready(function () {
150168
buttonMenuValidate();
151169
gameButtonValidation();
170+
gameButtonModifierValidation();
152171
});

gui/js/interactive/interactive-board.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,29 @@ function gameControlTypeSelect(){
151151
// Game Control Multi Add
152152
// This throws in a new input field for the multi button game controls.
153153
function gameControlMultiAdd(){
154-
var itemHTML = `
155-
<input class="form-control" type="text" placeholder="W" name="buttonPress" data-toggle="tooltip" data-placement="left" title="A key that will be pressed.">
156-
`;
157-
$('.multi-button-array').append(itemHTML);
154+
if( $('.multi-button-array input').length < 3){
155+
var itemHTML = `
156+
<input class="form-control" type="text" placeholder="shift" name="buttonPress" data-toggle="tooltip" data-placement="left" title="A modifier to press with the primary key. Accepts: control, alt, shift, or command(mac).">
157+
`;
158+
$('.multi-button-array').append(itemHTML);
158159

159-
// Setup autocomplete on new field.
160-
jqValidate.gameValidate();
160+
// Setup autocomplete on new field.
161+
jqValidate.gameModifierValidate();
161162

162-
// Setup tooltips
163-
$('.multi-button-array input[data-toggle="tooltip"]').tooltip()
163+
// Setup tooltips
164+
$('.multi-button-array input[data-toggle="tooltip"]').tooltip()
165+
} else {
166+
errorLogger.log("Sorry, you can only have three modifiers per button.");
167+
}
164168
}
165169

166170
// Game Control Multi Delete
167171
// This just deletes the last field in the multi button field list.
168172
function gameControlMultiDel(){
169-
$('.multi-button-array input').last().remove();
173+
// Dont delete the last one.
174+
if( $('.multi-button-array input').length > 1){
175+
$('.multi-button-array input').last().remove();
176+
}
170177
}
171178

172179
// Button Submission
@@ -204,12 +211,13 @@ function buttonSubmission(){
204211
var typeSettings = { "press": buttonPressed, "opposite": buttonOpposite};
205212
} else {
206213
// User has chosen the multi button option.
214+
var buttonPressed = $('.multi-button-key input').val();
207215
var buttonArray = [];
208216
$('.multi-button-array > input').each(function(){
209217
var val = $(this).val();
210218
buttonArray.push(val);
211219
})
212-
var typeSettings = { "press": buttonArray, "opposite": ""};
220+
var typeSettings = { "press": buttonPressed, "opposite": "", "modifiers": buttonArray};
213221
}
214222
} else if (buttonType == "Sound"){
215223
var filePath = $('.sound-file input').val();
@@ -420,15 +428,17 @@ function editButton(buttonID){
420428
if(buttonType === "Game Controls"){
421429
var press = typeSettings.press;
422430
var opposite = typeSettings.opposite;
423-
if(press instanceof Array){
431+
var modifiers = typeSettings.modifiers;
432+
if(modifiers instanceof Array){
424433
// Multi Button
425434

426435
// Clear everything already there.
427-
$('.multi-button-array').empty();
436+
$('.multi-button-key input').val(press);
437+
$('.multi-button-array input').remove();
428438

429439
// Add in the appropriate html.
430-
for(var item in press){
431-
var key = press[item];
440+
for(var item in modifiers){
441+
var key = modifiers[item];
432442

433443
// Add in a new input field.
434444
gameControlMultiAdd();

lib/interactive/game-controls/tactile/tactileProcessor.js

+30-23
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,27 @@ function tactile(report) {
2929
var typeSettings = button['typeSettings'];
3030
var key = typeSettings['press'];
3131
var oppositeKey = typeSettings['opposite'];
32+
var modifiers = typeSettings['modifiers'];
3233

33-
// If there is more than one key that should be pressed...
34-
if (key instanceof Array && isNaN(press) === false && press !== null){
35-
// These keys all need to be tapped.
36-
for(var i in key){
37-
var transKey = keyTranslator.translate(key[i]);
38-
tactileTap(transKey, press, buttonID);
39-
}
40-
} else if (key instanceof Array && isNaN(holding) === false && holding !== null){
41-
// These keys all need to be held.
42-
for(var i in key){
43-
var transKey = keyTranslator.translate(key[i]);
44-
tactileHold(transKey, holding, buttonID);
45-
}
34+
// Route button to correct handler for it's purpose.
35+
if(modifiers !== undefined && modifiers instanceof Array){
36+
// Multikey button
37+
multiKey(key, modifiers, buttonID);
4638
} else if (oppositeKey !== "") {
47-
// Not an array, does it have an opposite key to compare against?
48-
var key = keyTranslator.translate(key);
49-
var oppositeKey = keyTranslator.translate(oppositeKey);
39+
// Key comparison
5040
movement(key, oppositeKey, buttonID);
5141
} else if ( isNaN(holding) === false && holding !== null) {
52-
// Not an array, and we're getting holding stats. Hold this button.
53-
var key = keyTranslator.translate(key);
42+
// Holding key
5443
tactileHold(key, holding, buttonID);
5544
} else {
56-
// Not an array, and we're getting press stats. Just press this one.
57-
var key = keyTranslator.translate(key);
45+
// Tap it
5846
tactileTap(key, press, buttonID);
5947
}
6048
} else {
6149
// This button doesnt have press frequency or holding checked in dev lab.
6250
errorLog.log('Button '+rawid+' does not have press frequency or holding checked in the dev lab.');
6351
}
52+
6453
}
6554

6655
// Button Saves
@@ -105,8 +94,28 @@ function buttonSave(report) {
10594
}
10695
}
10796

97+
// Tactile Key Tap.
98+
function multiKey(key, modifiers, buttonID) {
99+
var key = keyTranslator.translate(key);
100+
101+
// Scrub the modifiers list and make a clean array.
102+
var cleanModifiers = [];
103+
for (var i in modifiers){
104+
var cleanButton = keyTranslator.translate(modifiers[i]);
105+
cleanModifiers.push(cleanButton);
106+
}
107+
108+
emulate.keyToggle(key, "down", cleanModifiers);
109+
110+
setTimeout(function() {
111+
emulate.keyToggle(key, "up", cleanModifiers);
112+
}, 30);
113+
}
114+
108115
// Movement Keys
109116
function movement(key, oppositeKey, buttonID) {
117+
var key = keyTranslator.translate(key);
118+
var oppositeKey = keyTranslator.translate(oppositeKey);
110119

111120
// Get saved states for related keys.
112121
var keyOne = global.buttonSaves[key] || 0;
@@ -164,12 +173,10 @@ function tactileTap(key, press, buttonID) {
164173

165174
setTimeout(function() {
166175
emulate.keyToggle(key, "up");
167-
}, 40);
176+
}, 30);
168177
}
169178
}
170179

171-
172-
173180
// Export main function
174181
exports.tactile = tactile;
175182
exports.buttonSaves = buttonSave;

0 commit comments

Comments
 (0)