--- title: System Modifier Keys Must Be Held During keyup Events impact: MEDIUM impactDescription: Modifier keys (ctrl, alt, shift, meta) behave differently with keyup - they must be held when the key is released type: gotcha tags: [vue3, events, keyboard, modifiers, keyup, shortcuts] --- # System Modifier Keys Must Be Held During keyup Events **Impact: MEDIUM** - When using system modifier keys (`.ctrl`, `.alt`, `.shift`, `.meta`) with `keyup` events, the modifier must still be pressed when the other key is released. Releasing the modifier key first will not trigger the event, causing keyboard shortcuts to appear broken. ## Task Checklist - [ ] Understand that `@keyup.ctrl` requires Ctrl to be held while releasing another key - [ ] Consider using `keydown` instead of `keyup` for modifier key combinations - [ ] Use `.exact` when you need precise modifier key control - [ ] Test keyboard shortcuts with proper key release order **Incorrect:** ```html ``` ```html ``` **Correct:** ```html ``` ```html ``` ```html ``` ## How System Modifiers Work with keyup ```javascript // Timeline of Ctrl+S keydown: // 1. User presses Ctrl (keydown fires) // 2. User presses S while holding Ctrl (keydown fires) // Timeline of Ctrl+S keyup: // 3. User releases S while holding Ctrl (keyup.ctrl.s fires!) // 4. User releases Ctrl (keyup fires, but not keyup.ctrl.s) // Common mistake: // 3. User releases Ctrl first (nothing fires for our handler) // 4. User releases S (keyup.s fires, but not keyup.ctrl.s) ``` ## System Modifier Keys ```html ``` ## The .exact Modifier ```html ``` ## Best Practice: Prefer keydown for Shortcuts ```html ``` ## Reference - [Vue.js Event Handling - Key Modifiers](https://vuejs.org/guide/essentials/event-handling.html#key-modifiers) - [Vue.js Event Handling - System Modifier Keys](https://vuejs.org/guide/essentials/event-handling.html#system-modifier-keys)