1234567891011121314151617181920212223 |
- // 监听键盘按下事件
- let isCtrlPressed = false;
- let isShiftPressed = false;
- document.addEventListener('keydown', (event) => {
- if (event.ctrlKey) isCtrlPressed = true;
- if (event.shiftKey) isShiftPressed = true;
- });
- document.addEventListener('keyup', (event) => {
- if (!event.ctrlKey) isCtrlPressed = false;
- if (!event.shiftKey) isShiftPressed = false;
- });
- // 发送按键状态给 background.js
- chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
- if (message.type === 'getKeyboardState') {
- sendResponse({
- ctrl: isCtrlPressed,
- shift: isShiftPressed
- });
- }
- });
|