mirror of
https://github.com/danbulant/console-hub
synced 2026-06-20 23:11:11 +00:00
Testing gamepad
This commit is contained in:
parent
79fae9716d
commit
355c050522
2 changed files with 60 additions and 0 deletions
|
|
@ -23,3 +23,55 @@ $(document).keypress((event) => {
|
|||
event.preventDefault();
|
||||
}
|
||||
})
|
||||
var keyBinds = new Map();
|
||||
var pressed = [];
|
||||
var gameLooper = 0;
|
||||
//Sending keys from gamepad
|
||||
function changeToGame(){
|
||||
//Called when game is running
|
||||
//reset events
|
||||
gamepad.off('press', 'start');
|
||||
gamepad.off('press', 'd_pad_left');
|
||||
gamepad.off('press', 'd_pad_right');
|
||||
gamepad.off('press', 'button_1');
|
||||
gamepad.off('press', 'button_2');
|
||||
//add custom ones
|
||||
keyBinds.foreach((val, key) => {
|
||||
gamepad.on('press', key, () => {
|
||||
pressed.push(val);
|
||||
})
|
||||
})
|
||||
|
||||
gameLooper = setInterval(() => {
|
||||
sendKeys(pressed);
|
||||
pressed = [];
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function changeToMenu(){
|
||||
clearInterval(gameLooper); //stop sending keys
|
||||
//Called when game is stopped
|
||||
//reset events
|
||||
gamepad.off('press', 'start');
|
||||
gamepad.off('press', 'd_pad_left');
|
||||
gamepad.off('press', 'd_pad_right');
|
||||
gamepad.off('press', 'button_1');
|
||||
gamepad.off('press', 'button_2');
|
||||
//restore original events
|
||||
gamepad.on('press', 'start', () => {
|
||||
showMainMenu();
|
||||
});
|
||||
|
||||
gamepad.on('press', 'd_pad_left', () => {
|
||||
goLeft();
|
||||
});
|
||||
gamepad.on('press', 'd_pad_right', () => {
|
||||
goRight();
|
||||
});
|
||||
gamepad.on('press', 'button_1', () => {
|
||||
select();
|
||||
});
|
||||
gamepad.on('press', 'button_2', () => {
|
||||
deselect();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,11 +27,19 @@ if(typeof require !== typeof undefined){
|
|||
files = arg;
|
||||
refreshFiles();
|
||||
})
|
||||
function sendKeys(arg){
|
||||
ipcRenderer.send('sendKeys', arg);
|
||||
return true;
|
||||
}
|
||||
var loc = window.location.pathname;
|
||||
var dir = loc.substring(1, loc.lastIndexOf('/'));//fix file:///, only on node
|
||||
ipcRenderer.send('listFiles', dir);
|
||||
} else {
|
||||
//no NODE integration, propably browser access
|
||||
function sendKeys(arg){
|
||||
return false;
|
||||
}
|
||||
toast('Missing node - features may not be available');
|
||||
$("div:has(#files)").hide();//Disable file system preview
|
||||
mainMenuItems.slice("files");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue