|
| 1 | +-- This script simulates an Alt+Tab sequence on Windows. |
| 2 | +-- Step 1: Hold down the Alt key. |
| 3 | +-- - The combo uses a modifier value of 0x04 (representing Alt) and sends key 0xE2 (the Alt key code). |
| 4 | +-- - Both hold_modifiers and hold_keys are enabled so that the Alt key remains pressed. |
| 5 | +-- - After sending, it waits 100ms before processing the next combo. |
| 6 | +-- |
| 7 | +-- Step 2: Press the Tab key while keeping Alt held. |
| 8 | +-- - The combo still uses the Alt modifier (0x04) and sends key 0x2B (Tab). |
| 9 | +-- - The key is held for 50ms and then the script waits 3000ms. |
| 10 | +-- |
| 11 | +-- Step 3: Simulate repeated Tab presses while Alt remains held. |
| 12 | +-- - A sequence of combos sends Tab (0x2B) with a hold period (e.g., 200ms) and then sends an empty key press with a wait period (e.g., 2000ms). |
| 13 | +-- |
| 14 | +-- Step 4: Press Esc to cancel the switcher and then release Alt. |
| 15 | +-- - First, a combo sends Esc (0x29) with an instant_release flag. |
| 16 | +-- - Finally, a combo with modifier 0x04 sends Alt (0xE2) with instant_release to clear the Alt hold. |
| 17 | +-- |
| 18 | +-- The expectation is that during the entire sequence, Alt (0xE2) remains held until we explicitly release it. |
| 19 | +-- The log should show active_modifiers = 0x04 while Alt is held and active_keys containing {226}. |
| 20 | +-- Finally, after the instant releases, both active_modifiers and active_keys should be cleared. |
| 21 | + |
| 22 | + |
| 23 | +-- send_key_combinations parameters documentation: |
| 24 | +-- ---------------------------------------------- |
| 25 | +-- send_key_combinations accepts a table (list) of key combo elements. |
| 26 | +-- Each element in the table represents a keystroke (or a set of keystrokes) and includes parameters |
| 27 | +-- that define how that keystroke is simulated. Here's a breakdown of each parameter: |
| 28 | +-- |
| 29 | +-- |
| 30 | +-- modifier: |
| 31 | +-- - A bitmask representing modifier keys (e.g., 0x04 for Alt). |
| 32 | +-- - This value is combined with the keys provided to simulate simultaneous key presses. |
| 33 | +-- |
| 34 | +-- keys: |
| 35 | +-- - A table of keycodes (in hexadecimal) to be sent. |
| 36 | +-- - Example: { 0xE2 } for the Alt key or { 0x2B } for the Tab key. |
| 37 | +-- - If omitted (nil), it can default to an empty table, which is useful for pure waits. |
| 38 | +-- |
| 39 | +-- hold_keys: |
| 40 | +-- - A boolean flag. |
| 41 | +-- - When true, the keys in this combo are added to the active_keys state and remain pressed until explicitly released. |
| 42 | +-- - This is used when you want to keep a key (like Alt) pressed across multiple combos. |
| 43 | +-- |
| 44 | +-- hold_modifiers: |
| 45 | +-- - A boolean flag. |
| 46 | +-- - When true, the modifier bits (e.g., 0x04 for Alt) are added to the active_modifiers state and are not cleared automatically. |
| 47 | +-- - This ensures that even if subsequent combos release keys, the modifier (Alt) stays active. |
| 48 | +-- |
| 49 | +-- hold: |
| 50 | +-- - An optional number (milliseconds) that specifies how long to hold the key press before releasing it. |
| 51 | +-- - During this period, the keys (and possibly modifiers) remain active. |
| 52 | +-- |
| 53 | +-- wait: |
| 54 | +-- - An optional number (milliseconds) to wait after processing the current combo before proceeding to the next combo. |
| 55 | +-- - Useful for adding delays between key sequences (e.g., waiting for the switcher UI to appear). |
| 56 | +-- |
| 57 | +-- instant_release: |
| 58 | +-- - A boolean flag. |
| 59 | +-- - When true, the specified keys (and possibly modifiers) are immediately released after being processed. |
| 60 | +-- - The release logic can clear the keys/modifiers unless they are being held by hold_keys/hold_modifiers. |
| 61 | +-- |
| 62 | +-- clear_keys: |
| 63 | +-- - An optional boolean flag. |
| 64 | +-- - When true, it forces an immediate reset by clearing all active keys and modifiers. |
| 65 | +-- |
| 66 | +-- |
| 67 | +-- |
| 68 | +-- |
| 69 | +-- |
| 70 | +-- How and why the Alt key remains pressed: |
| 71 | +-- - In the first combo, both hold_keys and hold_modifiers are set to true. |
| 72 | +-- - The Alt key is sent using its keycode (0xE2) along with the Alt modifier (0x04). |
| 73 | +-- - hold_keys ensures that the keycode 0xE2 is retained in the active_keys set. |
| 74 | +-- - hold_modifiers ensures that the modifier 0x04 is retained in the active_modifiers set. |
| 75 | +-- - This persistent state keeps Alt pressed across subsequent combos until a later combo explicitly releases it. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +-- Example script simulating Alt+Tab with detailed timing and release: |
| 80 | +send_key_combinations({ |
| 81 | + -- Step 1: Hold Alt (0xE2) |
| 82 | + -- - Send Alt key with modifier 0x04. |
| 83 | + -- - Both hold_modifiers and hold_keys are enabled so that Alt remains pressed. |
| 84 | + { modifier = 0x04, keys = { 0xE2 }, wait = 100, hold_modifiers = true, hold_keys = true }, |
| 85 | + |
| 86 | + -- Step 2: Press Tab (0x2B) while keeping Alt held. |
| 87 | + -- - Sends Tab while Alt remains active. |
| 88 | + -- - The Tab key is held for 50ms and then released, leaving Alt still pressed. |
| 89 | + { modifier = 0x04, keys = { 0x2B }, hold = 50, wait = 3000, hold_modifiers = true }, |
| 90 | + |
| 91 | + -- Step 3: Additional Tab presses to simulate switching windows. |
| 92 | + { modifier = 0x04, keys = { 0x2B }, hold = 200 }, |
| 93 | + { modifier = 0x04, wait = 2000 }, -- pure wait |
| 94 | + { modifier = 0x04, keys = { 0x2B }, hold = 200 }, |
| 95 | + { modifier = 0x04, wait = 2000 }, |
| 96 | + |
| 97 | + -- Step 4: Press Esc (0x29) to cancel the switcher. |
| 98 | + { modifier = 0x00, keys = { 0x29 }, instant_release = true }, |
| 99 | + |
| 100 | + -- Step 5: Release Alt. |
| 101 | + -- - Sends the Alt key with modifier 0x04 and instant_release to clear the held Alt state. |
| 102 | + { modifier = 0x04, keys = { 0xE2 }, instant_release = true }, |
| 103 | +}) |
0 commit comments