### Key Combination String Format Examples Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Examples illustrating the string format used to represent keyboard shortcut combinations, including combinations with Alt, Shift, and Ctrl keys. ```text "A+8" = Alt+8 ``` ```text "S+q" = Shift+Q ``` ```text "C+a" = Ctrl+A ``` ```text "AC+n" = Alt+Ctrl+N ``` ```text "CS+1" = Ctrl+Shift+1 ``` -------------------------------- ### Console Usage for Demo Shortcut 2 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Provides examples for manually saving and resetting the demo shortcut 2. Manual saving is generally not needed due to the auto-save feature. ```javascript window.saveDemoShortcut2(); // Manual save (usually not needed — auto-saves) window.resetDemoShortcut2(); // Reset to hardcoded default ``` -------------------------------- ### Reset Demo Shortcut 1 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Resets Demo Action 1 to its default state, removing any manually assigned key. Useful for testing the initial setup. ```javascript window.resetDemoShortcut1(); ``` -------------------------------- ### Get All Shortcuts in WME Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this snippet to inspect all shortcuts currently recognized by WME, helping to debug issues where a shortcut might not be registered correctly. Ensure you replace 'YourShortcutId' with the actual ID of the shortcut you are investigating. ```javascript // Check what WME sees for your shortcut wmeSDK.Shortcuts.getAllShortcuts().find(s => s.shortcutId === 'YourShortcutId'); ``` -------------------------------- ### Initialize WME SDK and Script Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Initializes the WME SDK and calls the script initialization function once the SDK is ready. Ensure this runs after WME is fully loaded. ```javascript let wmeSDK = null; // Initialize via SDK_INITIALIZED promise unsafeWindow.SDK_INITIALIZED.then(initScript); function initScript() { console.log('[DEMO] Initializing WME SDK...'); wmeSDK = getWmeSdk({ scriptId: 'wme-shortcut-demo', scriptName: 'Shortcut Demo', }); initializeShortcuts(); } ``` -------------------------------- ### Retrieve Demo Shortcut 1 Configuration Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Retrieves the saved configuration for Demo Action 1 from local storage. Use this to verify that manual saves have been persisted correctly. ```javascript localStorage.getItem('WMEShortcutDemo_Action1_Config'); ``` -------------------------------- ### 5-Step Pattern for WME Shortcuts Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home This outlines the standard sequence for implementing shortcuts in the WME SDK. It's crucial to follow these steps, especially deleting the old shortcut before creating a new one to prevent errors. ```text Step 1: Load saved config from localStorage Step 2: Delete old shortcut (CRITICAL - required before recreating) Step 3: Convert saved numeric format → string format Step 4: Create shortcut with converted keys (or null / hardcoded default) Step 5: Register save/reset functions on unsafeWindow ``` -------------------------------- ### Repository Structure Overview Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md Provides a high-level view of the repository structure, highlighting key files for shortcut implementation and testing. ```text WMESDK-KEYBOARD-SHORTCUT-IMPLEMENTATION-GUIDE/ ├── SHORTCUT_IMPLEMENTATION_GUIDE.md ← Read this first ├── WME-Shortcut-Demo.user.js ← Test this └── (This file) ``` -------------------------------- ### Initialize Shortcut with Manual Save Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home Use this pattern when users assign their own keys and must explicitly save the configuration via the console. It includes loading saved configurations, deleting old shortcuts, converting key formats, creating the new shortcut, and registering save/reset functions. ```javascript const initializeShortcut1 = () => { const shortcutId = 'WMEShortcutDemo_Action1'; const storageKey = 'WMEShortcutDemo_Action1_Config'; // Step 1: Load saved config let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) { console.error(`[SHORTCUT1] Error reading saved config: ${e}`); } // Step 2: Delete old shortcut (only if we have saved keys to restore) if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) { // Expected on first load } } // Step 3: Convert numeric → string let shortcutKeysToUse = null; if (savedConfig?.shortcutKeys) { shortcutKeysToUse = convertNumericShortcutToString(savedConfig.shortcutKeys) || null; } // Step 4: Create shortcut (null = user assigns via WME UI) wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'Demo Action 1', description: 'USER CUSTOMIZABLE - Assign keys, then run: window.saveDemoShortcut1() in console', shortcutKeys: shortcutKeysToUse, callback: () => { console.log('[SHORTCUT1] Callback triggered!'); // Your action code here } }); // Step 5: Register save/reset on unsafeWindow (accessible from browser console as window.xxx) unsafeWindow.saveDemoShortcut1 = function() { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (!shortcut) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); console.log(`[SHORTCUT1 SAVE] Saved: ${shortcut.shortcutKeys}`); }; unsafeWindow.resetDemoShortcut1 = function() { localStorage.removeItem(storageKey); console.log('[SHORTCUT1 RESET] Cleared. Reload page to apply.'); }; }; ``` -------------------------------- ### Manually Save Demo Shortcut 1 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Force a manual save for Demo Action 1. This is useful for testing persistence immediately after configuration changes. ```javascript window.saveDemoShortcut1(); ``` -------------------------------- ### Initialize Shortcut with Hardcoded Default and User Override Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this pattern when a sensible default key is needed for new users, with the ability for users to customize and save their own key bindings. It loads saved configurations, applies defaults if none exist, and registers functions to save or reset user preferences. ```javascript const initializeShortcut3 = () => { const shortcutId = 'WMEShortcutDemo_Action3'; const storageKey = 'WMEShortcutDemo_Action3_Config'; const HARDCODED_DEFAULT = 'A+9'; // Alt+9 — works on first load with no setup // Step 1: Load saved config let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) {} // Step 2: Delete old shortcut (only if restoring saved keys) if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) {} } // Step 3: Determine keys — saved custom OR fallback to hardcoded default let shortcutKeysToUse; if (savedConfig?.shortcutKeys) { shortcutKeysToUse = convertNumericShortcutToString(savedConfig.shortcutKeys) || null; console.log(`[SHORTCUT3] Using user-customized keys: ${shortcutKeysToUse}`); } else { shortcutKeysToUse = HARDCODED_DEFAULT; console.log(`[SHORTCUT3] Using hardcoded default: ${HARDCODED_DEFAULT}`); } // Step 4: Create shortcut wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'Demo Action 3', description: `HARDCODED DEFAULT (${HARDCODED_DEFAULT}) - Change keys, then run: window.saveDemoShortcut3()`, shortcutKeys: shortcutKeysToUse, callback: () => { console.log('[SHORTCUT3] Callback triggered!'); } }); // Step 5: Register save/reset unsafeWindow.saveDemoShortcut3 = function() { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (!shortcut?.shortcutKeys) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); console.log(`[SHORTCUT3 SAVE] Saved custom: ${shortcut.shortcutKeys}`); }; unsafeWindow.resetDemoShortcut3 = function() { localStorage.removeItem(storageKey); console.log('[SHORTCUT3 RESET] Cleared. Will revert to default on next load.'); }; }; ``` -------------------------------- ### Initialize Auto-Saving Shortcut (Pattern C) Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home Use this pattern when you want user-assigned keys to persist automatically without manual saving steps. It loads existing configurations, creates a shortcut, and sets up an interval to auto-save key changes every 2 seconds. ```javascript const initializeShortcut4 = () => { const shortcutId = 'WMEShortcutDemo_Action4'; const storageKey = 'WMEShortcutDemo_Action4_Config'; // Steps 1–4: identical to Pattern A (load, delete, convert, create) let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) {} if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) {} } let shortcutKeysToUse = null; if (savedConfig?.shortcutKeys) { shortcutKeysToUse = convertNumericShortcutToString(savedConfig.shortcutKeys) || null; } wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'Demo Action 4', description: 'AUTO-SAVE - Assign keys, automatically saved every 2 seconds!', shortcutKeys: shortcutKeysToUse, callback: () => { console.log('[SHORTCUT4] Callback triggered!'); } }); // Step 5: Auto-save interval — polls every 2 seconds for key changes let lastSavedKeys = savedConfig?.shortcutKeys || null; setInterval(() => { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (shortcut?.shortcutKeys && shortcut.shortcutKeys !== lastSavedKeys) { localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); lastSavedKeys = shortcut.shortcutKeys; console.log(`[SHORTCUT4 AUTO-SAVE] Saved: ${shortcut.shortcutKeys}`); } }, 2000); // Manual save still available as a fallback unsafeWindow.saveDemoShortcut4 = function() { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (!shortcut) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); lastSavedKeys = shortcut.shortcutKeys; console.log(`[SHORTCUT4 MANUAL SAVE] Saved: ${shortcut.shortcutKeys}`); }; unsafeWindow.resetDemoShortcut4 = function() { localStorage.removeItem(storageKey); console.log('[SHORTCUT4 RESET] Cleared. Reload page to apply.'); }; }; ``` -------------------------------- ### Retrieve Demo Shortcut 2 Configuration Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Retrieves the saved configuration for Demo Action 2 from local storage. This helps verify auto-save functionality and manual save persistence. ```javascript localStorage.getItem('WMEShortcutDemo_Action2_Config'); ``` -------------------------------- ### Retrieve Demo Shortcut 3 Configuration Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Retrieves the saved configuration for Demo Action 3 from local storage. Use this to confirm that custom key assignments are persisted after manual saving. ```javascript localStorage.getItem('WMEShortcutDemo_Action3_Config'); ``` -------------------------------- ### Run Demo Action 1 Console Command Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md This command is used to manually save the shortcut assignment for 'Demo Action 1' in the WME-Shortcut-Demo.user.js script. ```javascript window.saveDemoShortcut1() ``` -------------------------------- ### Access Demo Shortcut Configurations in Local Storage Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home Retrieve the saved configuration for specific demo actions from local storage. This allows direct inspection of stored shortcut data. ```javascript localStorage.getItem('WMEShortcutDemo_Action1_Config'); ``` ```javascript localStorage.getItem('WMEShortcutDemo_Action2_Config'); ``` ```javascript localStorage.getItem('WMEShortcutDemo_Action3_Config'); ``` ```javascript localStorage.getItem('WMEShortcutDemo_Action4_Config'); ``` -------------------------------- ### General Formula for Persistent Shortcuts Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md This formula outlines the common steps involved in loading, deleting, converting, and creating shortcuts, as well as registering event handlers or auto-save intervals. ```text 1. Load saved config from localStorage 2. Delete old shortcut (try-catch, only if saved keys exist) 3. Convert numeric → string ("4,56" → "A+8") 4. Create shortcut with converted keys (or null / hardcoded default) 5. Register unsafeWindow.saveXxx / unsafeWindow.resetXxx — OR — start auto-save interval (Pattern C) ``` -------------------------------- ### Initialize Auto-Save Shortcut (Pattern C) Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this pattern when you want user-assigned keys to persist automatically without manual saving. It loads existing configurations, creates the shortcut, and sets up an interval to auto-save key changes every 2 seconds. ```javascript const initializeShortcut4 = () => { const shortcutId = 'WMEShortcutDemo_Action4'; const storageKey = 'WMEShortcutDemo_Action4_Config'; // Steps 1–4: identical to Pattern A (load, delete, convert, create) let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) {} if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) {} } let shortcutKeysToUse = null; if (savedConfig?.shortcutKeys) { shortcutKeysToUse = convertNumericShortcutToString(savedConfig.shortcutKeys) || null; } wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'Demo Action 4', description: 'AUTO-SAVE - Assign keys, automatically saved every 2 seconds!', shortcutKeys: shortcutKeysToUse, callback: () => { console.log('[SHORTCUT4] Callback triggered!'); } }); // Step 5: Auto-save interval — polls every 2 seconds for key changes let lastSavedKeys = savedConfig?.shortcutKeys || null; setInterval(() => { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (shortcut?.shortcutKeys && shortcut.shortcutKeys !== lastSavedKeys) { localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); lastSavedKeys = shortcut.shortcutKeys; console.log(`[SHORTCUT4 AUTO-SAVE] Saved: ${shortcut.shortcutKeys}`); } }, 2000); // Manual save still available as a fallback unsafeWindow.saveDemoShortcut4 = function() { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (!shortcut) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); lastSavedKeys = shortcut.shortcutKeys; console.log(`[SHORTCUT4 MANUAL SAVE] Saved: ${shortcut.shortcutKeys}`); }; unsafeWindow.resetDemoShortcut4 = function() { localStorage.removeItem(storageKey); console.log('[SHORTCUT4 RESET] Cleared. Reload page to apply.'); }; }; ``` -------------------------------- ### Implement Hardcoded Default with Auto-Save Shortcut Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this pattern when you need a sensible default key on first load and automatic persistence without manual saving. It includes a hardcoded default, auto-saves changes every 2 seconds, and provides manual reset functionality. ```javascript const initializeShortcut2 = () => { const shortcutId = 'WMEShortcutDemo_Action2'; const storageKey = 'WMEShortcutDemo_Action2_Config'; const HARDCODED_DEFAULT = 'A+2'; // Alt+2 — works on first load with no setup // Step 1: Load saved config let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) {} // Step 2: Delete old shortcut (only if restoring saved keys) if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) {} } // Step 3: Determine keys — saved custom OR fallback to hardcoded default let shortcutKeysToUse; if (savedConfig?.shortcutKeys) { shortcutKeysToUse = convertNumericShortcutToString(savedConfig.shortcutKeys) || null; console.log(`[SHORTCUT2] Using user-customized keys: ${shortcutKeysToUse}`); } else { shortcutKeysToUse = HARDCODED_DEFAULT; console.log(`[SHORTCUT2] Using hardcoded default: ${HARDCODED_DEFAULT}`); } // Step 4: Create shortcut wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'Demo Action 2', description: `HARDCODED DEFAULT (${HARDCODED_DEFAULT}) + AUTO-SAVE - Change keys, auto-saves every 2 seconds!`, shortcutKeys: shortcutKeysToUse, callback: () => { console.log('[SHORTCUT2] Callback triggered!'); } }); // Step 5: Auto-save mechanism — monitors for changes every 2 seconds let lastSavedKeys = savedConfig?.shortcutKeys || null; const autoSaveInterval = setInterval(() => { try { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (shortcut && shortcut.shortcutKeys) { // If keys changed since last save, auto-save if (shortcut.shortcutKeys !== lastSavedKeys) { const configToSave = { shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, }; localStorage.setItem(storageKey, JSON.stringify(configToSave)); lastSavedKeys = shortcut.shortcutKeys; console.log(`[SHORTCUT2 AUTO-SAVE] Saved: ${shortcut.shortcutKeys}`); } } } catch (e) { console.error(`[SHORTCUT2 AUTO-SAVE] Error: ${e}`); } }, 2000); // Manual save function also available unsafeWindow.saveDemoShortcut2 = function() { const shortcut = wmeSDK.Shortcuts.getAllShortcuts().find(s => s.shortcutId === shortcutId); if (!shortcut) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); console.log(`[SHORTCUT2 MANUAL SAVE] Saved: ${shortcut.shortcutKeys}`); }; // Reset function to clear custom and revert to default unsafeWindow.resetDemoShortcut2 = function() { localStorage.removeItem(storageKey); console.log('[SHORTCUT2 RESET] Cleared. Reload page to revert to default.'); }; }; ``` -------------------------------- ### Retrieve Demo Shortcut 4 Configuration Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Retrieves the saved configuration for Demo Action 4 from local storage. This is useful for verifying auto-save persistence. ```javascript localStorage.getItem('WMEShortcutDemo_Action4_Config'); ``` -------------------------------- ### Inspect All Shortcuts Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this command to retrieve all currently registered shortcuts. You can then filter this list by shortcut ID to find specific configurations. ```javascript wmeSDK.Shortcuts.getAllShortcuts(); wmeSDK.Shortcuts.getAllShortcuts().find(s => s.shortcutId === 'WMEShortcutDemo_Action1'); ``` -------------------------------- ### Initialize Persistent Shortcut with Manual Save Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this pattern when users assign their own keys and must explicitly save the configuration via the browser console. It loads saved configurations, deletes old shortcuts, converts key formats, creates new shortcuts, and registers save/reset functions. ```javascript const initializeShortcut1 = () => { const shortcutId = 'WMEShortcutDemo_Action1'; const storageKey = 'WMEShortcutDemo_Action1_Config'; // Step 1: Load saved config let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) { console.error(`[SHORTCUT1] Error reading saved config: ${e}`); } // Step 2: Delete old shortcut (only if we have saved keys to restore) if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) { // Expected on first load } } // Step 3: Convert numeric → string let shortcutKeysToUse = null; if (savedConfig?.shortcutKeys) { shortcutKeysToUse = convertNumericShortcutToString(savedConfig.shortcutKeys) || null; } // Step 4: Create shortcut (null = user assigns via WME UI) wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'Demo Action 1', description: 'USER CUSTOMIZABLE - Assign keys, then run: window.saveDemoShortcut1() in console', shortcutKeys: shortcutKeysToUse, callback: () => { console.log('[SHORTCUT1] Callback triggered!'); // Your action code here } }); // Step 5: Register save/reset on unsafeWindow (accessible from browser console as window.xxx) unsafeWindow.saveDemoShortcut1 = function() { const allShortcuts = wmeSDK.Shortcuts.getAllShortcuts(); const shortcut = allShortcuts.find(s => s.shortcutId === shortcutId); if (!shortcut) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); console.log(`[SHORTCUT1 SAVE] Saved: ${shortcut.shortcutKeys}`); }; unsafeWindow.resetDemoShortcut1 = function() { localStorage.removeItem(storageKey); console.log('[SHORTCUT1 RESET] Cleared. Reload page to apply.'); }; }; ``` -------------------------------- ### Manually Save Demo Shortcut 2 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Force a manual save for Demo Action 2. While this action typically auto-saves, manual saving can be used for immediate persistence testing. ```javascript window.saveDemoShortcut2(); ``` -------------------------------- ### Minimal Template for Pattern A Shortcut Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use this template to create a new keyboard shortcut. Remember to change the `shortcutId`, `storageKey`, `name`, `unsafeWindow.saveMyAction`, and `unsafeWindow.resetMyAction` values to match your script's requirements. The callback function is where your custom action code should be placed. ```javascript const initializeMyShortcut = () => { const shortcutId = 'MyScript_Action1'; // ← change this const storageKey = 'MyScript_Action1_Config'; // ← change this let savedConfig = null; try { const saved = localStorage.getItem(storageKey); if (saved) savedConfig = JSON.parse(saved); } catch (e) {} if (savedConfig?.shortcutKeys) { try { wmeSDK.Shortcuts.deleteShortcut({ shortcutId }); } catch (e) {} } const shortcutKeysToUse = savedConfig?.shortcutKeys ? convertNumericShortcutToString(savedConfig.shortcutKeys) || null : null; wmeSDK.Shortcuts.createShortcut({ shortcutId, name: 'My Action', // ← change this description: 'Run: window.saveMyAction() in console to persist keys', shortcutKeys: shortcutKeysToUse, callback: () => { // ← your action code here } }); unsafeWindow.saveMyAction = function() { // ← change this const shortcut = wmeSDK.Shortcuts.getAllShortcuts().find(s => s.shortcutId === shortcutId); if (!shortcut) return; localStorage.setItem(storageKey, JSON.stringify({ shortcutId: shortcut.shortcutId, name: shortcut.name, description: shortcut.description, shortcutKeys: shortcut.shortcutKeys, })); console.log(`[SAVE] Saved: ${shortcut.shortcutKeys}`); }; unsafeWindow.resetMyAction = function() { // ← change this localStorage.removeItem(storageKey); console.log('[RESET] Cleared. Reload page to apply.'); }; }; ``` -------------------------------- ### Debug Shortcut Configuration in WME Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home Use this snippet to inspect the shortcut configuration as seen by WME. This helps verify if your shortcut is registered correctly and identify potential discrepancies. ```javascript wmeSDK.Shortcuts.getAllShortcuts().find(s => s.shortcutId === 'YourShortcutId'); ``` -------------------------------- ### Clear All Demo Shortcut Configurations Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Removes all saved configurations for the demo shortcuts from local storage. This is useful for resetting the testing environment to its initial state. ```javascript ['WMEShortcutDemo_Action1_Config','WMEShortcutDemo_Action2_Config', 'WMEShortcutDemo_Action3_Config','WMEShortcutDemo_Action4_Config'] .forEach(k => localStorage.removeItem(k)); ``` -------------------------------- ### Test Results Verification Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md This section outlines the steps and expected outcomes for verifying keyboard shortcut functionality, including UI assignment, persistence, and callback triggering. ```text Assign Alt+8 via WME UI ↓ Save config: "4,56" ↓ Page reload ↓ Convert "4,56" → "A+8" ↓ Press Alt+8 → Callback triggers ✓ ``` -------------------------------- ### Reset Demo Shortcut Configurations Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home Reset demo shortcuts to their default states. For 'Demo Action 3', this reverts to its hardcoded default key. ```javascript window.resetDemoShortcut1(); ``` ```javascript window.resetDemoShortcut2(); ``` ```javascript window.resetDemoShortcut3(); // Reverts to hardcoded default (Alt+9) ``` ```javascript window.resetDemoShortcut4(); ``` -------------------------------- ### Test Shortcut Conversion Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md This snippet allows you to test the `convertNumericShortcutToString` function directly in the WME console. It helps verify that numeric shortcut representations are correctly converted to their string equivalents. Run this after your script has loaded. ```javascript // Test the converter directly in console // (run inside WME after the script loads) const result = convertNumericShortcutToString("4,56"); console.log(result); // Expected: "A+8" ``` -------------------------------- ### Manually Save Demo Shortcut Configurations Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/wiki/Home Manually trigger the save function for demo actions. This is typically used for actions that do not auto-save. ```javascript window.saveDemoShortcut1(); ``` ```javascript window.saveDemoShortcut2(); ``` ```javascript window.saveDemoShortcut3(); ``` ```javascript window.saveDemoShortcut4(); // Force save (usually auto-saves) ``` -------------------------------- ### Force Save Demo Shortcut 4 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Force a save for Demo Action 4. This action usually auto-saves, but this command ensures immediate persistence for testing. ```javascript window.saveDemoShortcut4(); // Force save (usually auto-saves) ``` -------------------------------- ### Save Demo Action 3 Console Command Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md This command saves a custom shortcut assignment for 'Demo Action 3' in the WME-Shortcut-Demo.user.js script. ```javascript window.saveDemoShortcut3() ``` -------------------------------- ### Manually Save Demo Shortcut 3 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Force a manual save for Demo Action 3. This is used to persist custom key assignments, overriding the hardcoded default. ```javascript window.saveDemoShortcut3(); ``` -------------------------------- ### Reset Demo Shortcut 4 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Resets Demo Action 4, removing any assigned key and returning it to an unassigned state. This is useful for testing the initial unassigned configuration. ```javascript window.resetDemoShortcut4(); ``` -------------------------------- ### Reset Demo Shortcut 2 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Resets Demo Action 2, reverting to its hardcoded default key assignment. This is useful for verifying the default behavior after customization. ```javascript window.resetDemoShortcut2(); ``` -------------------------------- ### Convert Numeric Shortcut to String Format Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Converts WME's internal numeric shortcut format (e.g., "4,56") to the string format required by `createShortcut()` (e.g., "A+8"). Handles modifier bitmasks and key codes for various keys. ```javascript const convertNumericShortcutToString = (numericFormat) => { if (!numericFormat || typeof numericFormat !== 'string') return null; const parts = numericFormat.split(','); if (parts.length !== 2) return null; const modifierBitmask = parseInt(parts[0], 10); const keyCode = parseInt(parts[1], 10); if (isNaN(modifierBitmask) || isNaN(keyCode)) return null; // Build modifier string in order: A, C, S let modifiers = ''; if (modifierBitmask & 4) modifiers += 'A'; // Alt if (modifierBitmask & 1) modifiers += 'C'; // Ctrl if (modifierBitmask & 2) modifiers += 'S'; // Shift // Convert keyCode to character/representation let keyRepresentation; if (keyCode >= 48 && keyCode <= 57) { keyRepresentation = String.fromCharCode(keyCode); // Numbers 0-9 } else if (keyCode >= 65 && keyCode <= 90) { keyRepresentation = String.fromCharCode(keyCode).toLowerCase(); // Letters A-Z } else { keyRepresentation = String(keyCode); // Special keys } return modifiers ? modifiers + '+' + keyRepresentation : keyRepresentation; }; ``` -------------------------------- ### Reset Demo Action 3 Console Command Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md This command resets the shortcut assignment for 'Demo Action 3' back to its default value in the WME-Shortcut-Demo.user.js script. ```javascript window.resetDemoShortcut3() ``` -------------------------------- ### Reset Demo Action 2 Console Command Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md This command resets the shortcut assignment for 'Demo Action 2' back to its default value in the WME-Shortcut-Demo.user.js script. ```javascript window.resetDemoShortcut2() ``` -------------------------------- ### Reset Demo Shortcut 3 Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Resets Demo Action 3, reverting to its hardcoded default key assignment (Alt+9). This is used to test the fallback to the default when custom saves are not performed. ```javascript window.resetDemoShortcut3(); // Reverts to hardcoded default (Alt+9) ``` -------------------------------- ### Console Usage for Saving and Resetting Shortcuts Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Use these console commands to manage user-defined shortcuts. `saveDemoShortcut3()` overrides the default with the current assignment, while `resetDemoShortcut3()` reverts to the hardcoded default on the next load. ```javascript window.saveDemoShortcut3(); // Override default with current assignment ``` ```javascript window.resetDemoShortcut3(); // Revert to hardcoded default (Alt+9) ``` -------------------------------- ### Console Usage for Auto-Save Shortcut Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Optional console commands to manually trigger a save or reset the shortcut assignments. Auto-save typically handles persistence, but these provide fallback control. ```javascript window.saveDemoShortcut4(); // Force immediate save ``` ```javascript window.resetDemoShortcut4(); // Clear assignment ``` -------------------------------- ### Reset Demo Action 4 Console Command Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md This command clears the shortcut assignment for 'Demo Action 4', resetting it in the WME-Shortcut-Demo.user.js script. ```javascript window.resetDemoShortcut4() ``` -------------------------------- ### Console Usage for Saving and Resetting Shortcuts Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md These commands are used in the browser console to interact with the manually saved shortcut. Use `saveDemoShortcut1()` to save the current key assignment and `resetDemoShortcut1()` to clear the saved assignment. ```javascript window.saveDemoShortcut1(); // Save current assignment ``` ```javascript window.resetDemoShortcut1(); // Clear saved assignment ``` -------------------------------- ### Modifier Bitmask Mapping Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/README.md Understand the bit position mapping for modifiers (Ctrl, Shift, Alt) and their combined values. ```text Bit Position Mapping: 1 = Ctrl (C) 2 = Shift (S) 4 = Alt (A) Combined Values: 1 = C 2 = S 3 = CS 4 = A 5 = AC 6 = AS 7 = ACS ``` -------------------------------- ### Call Exposed Function via window Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md From the browser console, you can call functions exposed via `unsafeWindow` using the global `window` object. Note that `unsafeWindow` itself is not available in the browser console. ```javascript window.saveDemoShortcut1(); // ✅ works in browser console ``` -------------------------------- ### Expose Function to Page via unsafeWindow Source: https://github.com/kid4rm90s/wmesdk-persistent-keyboard-shortcut-guide/blob/master/SHORTCUT_IMPLEMENTATION_GUIDE.md Inside a Tampermonkey script, use `unsafeWindow` to expose functions that can be called from the page's context. This is useful for making script functions accessible from the browser console. ```javascript unsafeWindow.saveDemoShortcut1 = function() { ... }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.