window.addEventListener('keydown', (ev: KeyboardEvent) => {
	if (document.activeElement && document.activeElement.nodeName != 'INPUT') {
		if ((isWin() && ev.ctrlKey) || (isMac() && ev.metaKey)) {
			switch (ev.key) {
				case 'c':
					ev.preventDefault();
					if (PageHandler.currentPageID && KeyHandler.selected.length == 1) {
						UndeckedClipboard.copyKey(
							parseInt(KeyHandler.selected[0].split(',')[0]),
							parseInt(KeyHandler.selected[0].split(',')[1])
						);
					}
					break;

				case 'x':
					ev.preventDefault();
					if (PageHandler.currentPageID && KeyHandler.selected.length == 1) {
						UndeckedClipboard.cutKey(
							parseInt(KeyHandler.selected[0].split(',')[0]),
							parseInt(KeyHandler.selected[0].split(',')[1])
						);
					}
					break;

				case 'v':
					ev.preventDefault();
					if (PageHandler.currentPageID && KeyHandler.selected.length == 1) {
						UndeckedClipboard.pasteKey(
							parseInt(KeyHandler.selected[0].split(',')[0]),
							parseInt(KeyHandler.selected[0].split(',')[1])
						);
					}
					break;

				case 'g':
					ev.preventDefault();
					if (PageHandler.currentPageID && KeyHandler.selected.length == 1) {
						UndeckedClipboard.copyGhostKey(
							parseInt(KeyHandler.selected[0].split(',')[0]),
							parseInt(KeyHandler.selected[0].split(',')[1])
						);
					}
					break;
			}
		} else {
			switch (ev.key) {
				case 'Delete':
					var x = parseInt(KeyHandler.selected[0].split(',')[0]);
					var y = parseInt(KeyHandler.selected[0].split(',')[1]);
					socket.emit('page', 'operation', 'delete', PageHandler.currentPageID, x, y);
					Editor.close();
					KeyHandler.select(String(x), String(y));
					break;
			}
		}
	}
});
