add keybinding

This commit is contained in:
Gerome Matilla 2020-06-04 15:09:22 +08:00
parent fdd1f0296f
commit af07931c2a
4 changed files with 33 additions and 2 deletions

View File

@ -234,5 +234,6 @@
<script src="js/centered-box.js"></script> <script src="js/centered-box.js"></script>
<script src="js/mobile-swipe-event.js"></script> <script src="js/mobile-swipe-event.js"></script>
<script src="js/mobile-swipe-callback.js"></script> <script src="js/mobile-swipe-callback.js"></script>
<script src="js/keybindings.js"></script>
</body> </body>
</html> </html>

31
js/keybindings.js Normal file
View File

@ -0,0 +1,31 @@
let keysPressed = {};
document.addEventListener(
'keydown',
(event) => {
event.preventDefault();
keysPressed[event.key] = true;
// Open dashboard
if (keysPressed['Alt'] && event.key === 's') {
toggleDashboard();
return;
} else if (keysPressed['Alt'] && event.key === 'e') {
toggleWebMenu();
return;
} else if (keysPressed['Alt'] && event.key === 'x') {
toggleWeatherScreen();
return;
}
}
);
document.addEventListener(
'keyup',
(event) => {
delete keysPressed[event.key];
}
);

View File

@ -265,7 +265,7 @@ const toggleWeatherScreen = () => {
} else if (dashboard.classList.contains('showRightDashboard')) { } else if (dashboard.classList.contains('showRightDashboard')) {
console.log('dashboard is open, closing...'); console.log('dashboard is open, closing...');
hideDashboard(); hideDashboard();
return; // return;
} }
// Toggle center box // Toggle center box

View File

@ -226,7 +226,6 @@ const toggleWebMenu = () => {
} else if (dashboard.classList.contains('showRightDashboard')) { } else if (dashboard.classList.contains('showRightDashboard')) {
console.log('dashboard is open, closing...'); console.log('dashboard is open, closing...');
hideDashboard(); hideDashboard();
return;
} }
// Toggle center box // Toggle center box