Last active
January 10, 2025 11:39
-
-
Save 70853n/ac6648207389bc868c5998da7502a397 to your computer and use it in GitHub Desktop.
An AutoHotkey v2 script for writing international characters on the US keyboard layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; Allows for international characters on the US layout | |
| ; To cycle through variations press and hold the desired character, | |
| ; then press and release the space bar to select the next variation. | |
| ; ----------------------------------------------------------------------------- | |
| ; CONFIGURATION | |
| ; ----------------------------------------------------------------------------- | |
| a:: | |
| +a:: | |
| { | |
| variations := A_ThisHotkey == "a" | |
| ? ['a', 'ä', 'à', 'á', 'â'] | |
| : ['A', 'Ä', 'À', 'Á', 'Â'] | |
| OfferVariations("a", variations) | |
| } | |
| a up:: return | |
| +a up:: return | |
| e:: | |
| +e:: | |
| { | |
| variations := A_ThisHotkey == "e" | |
| ? ['e', 'ë', 'è', 'é', 'ê'] | |
| : ['E', 'Ë', 'È', 'É', 'Ê'] | |
| OfferVariations("e", variations) | |
| } | |
| e up:: return | |
| +e up:: return | |
| i:: | |
| +i:: | |
| { | |
| variations := A_ThisHotkey == "i" | |
| ? ['i', 'ï', 'ì', 'í', 'î'] | |
| : ['I', 'Ï', 'Ì', 'Í', 'Î'] | |
| OfferVariations("i", variations) | |
| } | |
| i up:: return | |
| +i up:: return | |
| o:: | |
| +o:: | |
| { | |
| variations := A_ThisHotkey == "o" | |
| ? ['o', 'ö', 'ò', 'ó', 'ô'] | |
| : ['O', 'Ö', 'Ò', 'Ó', 'Ô'] | |
| OfferVariations("o", variations) | |
| } | |
| o up:: return | |
| +o up:: return | |
| u:: | |
| +u:: | |
| { | |
| variations := A_ThisHotkey == "u" | |
| ? ['u', 'ü', 'ù', 'ú', 'û'] | |
| : ['U', 'Ü', 'Ù', 'Ú', 'Û'] | |
| OfferVariations("u", variations) | |
| } | |
| u up:: return | |
| +u up:: return | |
| n:: | |
| +n:: | |
| { | |
| variations := A_ThisHotkey == "n" | |
| ? ['n', 'ñ'] | |
| : ['N', 'Ñ'] | |
| OfferVariations("n", variations) | |
| } | |
| n up:: return | |
| +n up:: return | |
| c:: | |
| +c:: | |
| { | |
| variations := A_ThisHotkey == "c" | |
| ? ['c', 'ç'] | |
| : ['C', 'Ç'] | |
| OfferVariations("c", variations) | |
| } | |
| c up:: return | |
| +c up:: return | |
| s:: | |
| +s:: | |
| { | |
| variations := A_ThisHotkey == "s" | |
| ? ['s', 'ß'] | |
| : ['S', 'ß'] | |
| OfferVariations("s", variations) | |
| } | |
| s up:: return | |
| +s up:: return | |
| y:: | |
| +y:: | |
| { | |
| variations := A_ThisHotkey == "y" | |
| ? ['y', 'ÿ'] | |
| : ['Y', 'Ÿ'] | |
| OfferVariations("y", variations) | |
| } | |
| y up:: return | |
| +y up:: return | |
| ; ----------------------------------------------------------------------------- | |
| ; BUSINESS LOGIC | |
| ; ----------------------------------------------------------------------------- | |
| OfferVariations(hotkey, variations) { | |
| KeyWait hotkey, "D" | |
| maxVariationIndex := variations.Length | |
| currentVariationIndex := 1 | |
| Send variations[currentVariationIndex] | |
| While (IsPhysicallyPressed(hotkey)) { | |
| if(A_TimeSinceThisHotkey < 200) { | |
| continue | |
| } | |
| for selectorKey in ["Space", 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] { | |
| if(!IsPhysicallyPressed(hotkey)) { | |
| break | |
| } | |
| if(IsPhysicallyPressed(selectorKey)) { | |
| nextVariationIndex := (selectorKey = "Space") | |
| ? CycleToNextValidIndex(currentVariationIndex, maxVariationIndex) | |
| : AsValidIndex(selectorKey, maxVariationIndex) | |
| nextVariation := variations[nextVariationIndex] | |
| SendReplaceWith(nextVariation) | |
| currentVariationIndex := nextVariationIndex | |
| KeyWait selectorKey, "L" | |
| break | |
| } | |
| } | |
| } | |
| } | |
| IsPhysicallyPressed(hotkey) { | |
| return GetKeyState(hotkey, "P") | |
| } | |
| SendReplaceWith(character) { | |
| Send "{Backspace}" | |
| Send "{Backspace}" | |
| Send character | |
| } | |
| CycleToNextValidIndex(currentIndex, maxIndex) { | |
| return Max(Mod(currentIndex + 1, maxIndex + 1), 1) | |
| } | |
| AsValidIndex(nextIndex, maxIndex) { | |
| return nextIndex > 1 && nextIndex <= maxIndex | |
| ? nextIndex | |
| : 1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment