Mapping Swedish character hotkeys in MacOS to Windows 10 - autohotkey

I want to map the Swedish characters å,ä,ö,Å,Ä,Ö to the MacOS hotkeys, but I want it to work under Windows 10 since at work I use a Windows machine and I do not want to keep switching back and forth from a US to Swedish keyboard layout. I think Autohotkey will be appropriate for this.
The MacOS mappings are:
Option+a = å
Shift+Option+a = Å
Option + u, then a = ä
Option + u, then shift + A = Ä
Option + u, then o = ö
Option + u, then shift + O = Ö
Instead of using the option key in Windows (since it doesn't exist) I will use the Left Windows key.
So far I have the script:
#u::
Input Key, L1
if Key=a
{
Send, ä
}
if Key=o
{
Send, ö
}
return
#a::
Send, å
return
This works for the lowercase characters but I am not sure how to implement the upper case characters.

user3419297's answer didn't work for me but I was able to use parts of it to get the code to work properly. I have posted it below in case anyone is wondering how I was able to get it to work.
#u::
Input, Key, L1
if GetKeyState("LShift")
{
if Key=a
{
Send, Ä
}
if Key=o
{
Send, Ö
}
}
else
{
if Key=a
{
Send, ä
}
if Key=o
{
Send, ö
}
}
return
<#a:: Send, å
<#+a:: Send, Å

Related

AutoHotKey v2.0.2: How to trigger HotKey on square bracket

I am trying to remap the opening square bracket ([) to a lower case u-umlaut (ü) and the opening curly bracket ({ / Shift+[) to the upper case U-umlaut (Ü) on a US keyboard layout using a AutoHotkey script.
The following works very well with ; to ö and : to Ö but the Variantes for ü and Ü don't. I suspect it's because a square bracket has a special meaning but there is no error about Syntax and AutoHotkey's escape Syntax with ` does not apply here.
I believe that the problem is the trigger $[:: because the first block with KeyWait alone without the second Up part does not prevent me typing [ while it does when I try that with ;.
Please explain what I am doing wrong.
#Requires AutoHotkey v2.0
#SingleInstance Force
LongPressDelay := 220
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; O-Umlaut | ; => ö und : => Ö
$;::
{
KeyWait ";"
return
}
$; Up::
{
If (A_PriorHotKey = "$;" AND A_TimeSincePriorHotkey < LongPressDelay)
Send ";"
else
Send "ö"
return
}
$+;::
{
KeyWait ";"
return
}
$+; Up::
{
If (A_PriorHotKey = "$+;" AND A_TimeSincePriorHotkey < LongPressDelay)
Send ":"
else
Send "Ö"
return
}
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; U-Umlaut| [ => ü und { => Ü
$[::
{
KeyWait "["
return
}
$[ Up::
{
If (A_PriorHotKey = "$[" AND A_TimeSincePriorHotkey < LongPressDelay)
Send "["
else
Send "ü"
return
}
$+[::
{
KeyWait "["
return
}
$+[ Up::
{
If (A_PriorHotKey = "$+[" AND A_TimeSincePriorHotkey < LongPressDelay)
Send "{"
else
Send "Ü"
return
}
; EDIT: My working solution per user3419297's answer
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; U-Umlaut| [ => ü und { => Ü
$SC01A::
{
KeyWait "SC01A"
return
}
$SC01A Up::
{
If (A_PriorHotKey = "$SC01A" AND A_TimeSincePriorHotkey < LongPressDelay)
Send "["
else
Send "ü"
return
}
$+SC01A::
{
KeyWait "SC01A"
return
}
$+SC01A Up::
{
If (A_PriorHotKey = "$+SC01A" AND A_TimeSincePriorHotkey < LongPressDelay)
SendText "{"
else
Send "Ü"
return
}
Script based on https://www.autohotkey.com/board/topic/80697-long-keypress-hotkeys-wo-modifiers/?p=689354
Context:
As a Developer it's super helpful to code using the US keyboard layout because all the special characters are within easy reach. As a native German speaker I'd like to access our beloved Umlauts at their traditional spots because I'm used to it.
On MacOS I solved this with Karabiner and Umlauts on long press. I want to replicate this on Windows.
In the rare case where a key has no name or the standard code doesn't work, Hotkeys can be triggered by using the 3-digit hexadecimal scan code (SC) of a key.
The scan code of a key can be determined by following the steps at Special Keys:
Run a script with keyboard hook
open the AutoHotkey window (context menu in systray, Open item)
go to View > Key History and script info
type the key
hit F5 to see the code
Trying the same right here, using a different code though.
https://www.autohotkey.com/boards/viewtopic.php?f=9&t=99809
I managed to migrate it to V2 and changed the keys to match the German Keyboard layout.
[ = ü
' = ä
; = ö
- = ß
Please feel free to try:
$[::
$+[::
$'::
$+'::
$;::
$+;::
$-::
{
umlaut_pairs := Map("$[" , "ü", "$'" , "ä", "$;" , "ö", "$-" , "ß", "$+[" , "Ü", "$+'" , "Ä", "$+;" , "Ö")
umlaut := umlaut_pairs[A_ThisHotkey]
Send SubStr(A_ThisHotkey,2) ; input the letter first, otherwise input order might be wrong
KeyWait Substr(A_ThisHotkey,-1), "T0.2" ; call only the specific character without "$" or "+" and show input of the pressed key
if(A_TimeSinceThisHotkey>200) ; if pressed more than 200ms
{
Send "{BackSpace}" ; backspace previous letter
Send umlaut_pairs[A_ThisHotkey] ; Replace acc. to the map
KeyWait Substr(A_ThisHotkey,-1), "T0.2"
; }
}
}

Autohotkey script to bookmark to a specific folder

I'm using Firefox and I was looking for an autohotkey script which would enable me to skip the whole series of clicks when I bookmark a page in a specific folder and replace it with a single keyboard shortcut.
Although I've read forum threads on Autohotkey forum and here I still don't know how to make a working script that would reduce bookmarking a page to hitting a keyboard shortcut and the initial letter of the folder where I want to store that page. Using KeyWait command I've made it work for a single folder and don't know how to make it work for any letter or a number that I could possibly use as a name for a bookmark folder. Say I have a folder named XXXX, this script does send the webpage to the XXXX folder after hitting the assigned shortcut and the letter x (MouseClick command is needed to focus the window with folder in the Bookmark Dialog pane):
!+^w::
Send,^d
Sleep,400
MouseClick,Left,864,304
Sleep,400
KeyWait, x ,D
Sleep, 400
Send,^{Enter}
return
I don't know how to make this script work for any letter or number, not only for a single one. Also a big problem with this script is that it blocks the keyboard until I hit X key. If I have that page bookmarked already, hitting escape to remove the bookmark pane will block the keyboard and I can unblock it only if I rerun the autohotkey script.
I've also tried using Input command as the contributors the Autohotkey forum pages suggested, but it didn't work either, because I don't understand how the Input command works. I did make it work for a single letter as the above script with KeyWait, but that's the best I could do. This script also blocks the keyboard until the letter is hit:
!+^w::
Send,^d
MouseClick,Left,864,304
Sleep,400
Input, Character, L1
If Character = t
Send, t
Sleep,400
Send,^{Enter}
return
Hope someone can help me with this, it would be convenient simplifying the bookmarking process in Firefox this way.
I have a nice idea. This will open the add bookmark dialog and navigate you into the folder selection part and expand all folders.
All you need to do is enter the folders name (or a part of it) and it will get selected automatically. When you're done, just hit enter.
!+^w:: ;Hotkey: Ctrl+Alt+Shift+w
Send, ^d ;send Ctrl+d to open the add-bookmark dialog
Sleep, 500 ;wait for the dialog to open
Send, {Tab}{Tab}{Enter} ;navigate into the folder selection
Sleep, 300 ;wait to make sure we are there
Send,{Home} ;select the first item in the list
;The following line should expand all the folders so that you can just type the folders name to search for it
Loop, 100 { ;Increase the number if it doesn't expand all folders
SendInput, {Right}{Down} ;expand folders
}
Send, {Home} ;navigate to the first item in the list again
Input, L, V L1 T2 ;wait until you start typing a folder name (if you just wait 2 seconds, the bookmark won't be created)
If (ErrorLevel = "Timeout") {
Send, {Tab 5} ;press tab 5 times to navigate to the cancel button
Send, {Enter} ;cancel the bookmark
Return ;end of the hotkey
}
Loop { ;wait until you haven't typed a new letter for 0.4 seconds
Input, L, V L1 T0.4
If (ErrorLevel = "Timeout")
Break
}
Send, {Tab 4} ;press tab 4 times to navigate to the enter button
Send, {Enter} ;save the bookmark
Return
My variant.
Press f1 to create bookmark in folder test1.
Press f2 to create bookmark in folder test2.
SetBatchLines, -1
Folders := {F1: "test1", F2: "test2"}
#IfWinActive, ahk_class MozillaWindowClass
F1::
F2::
Folder := Folders[A_ThisHotkey]
Send, ^d
AccFirefox := Acc_ObjectFromWindow(WinExist("ahk_class MozillaWindowClass"))
AccElem := SearchElement(AccFirefox, ROLE_SYSTEM_LISTITEM := 0x22, Folder, "")
AccElem.accDoDefaultAction(0)
sleep 100
Send {Enter}
msgbox done
return
#IfWinActive
SearchElement(ParentElement, params*)
{
found := 1
for k, v in params {
(k = 1 && ParentElement.accRole(0) != v && found := "")
(k = 2 && ParentElement.accName(0) != v && found := "")
(k = 3 && ParentElement.accValue(0) != v && found := "")
}
if found
Return ParentElement
for k, v in Acc_Children(ParentElement)
if obj := SearchElement(v, params*)
Return obj
}
Acc_Init()
{
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromWindow(hWnd, idObject = 0)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
Return ComObjEnwrap(9,pacc,1)
}
Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
Acc_Error(p="") {
static setting:=0
return p=""?setting:setting:=p
}
Acc_Children(Acc) {
if ComObjType(Acc,"Name") != "IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else {
Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
Loop %cChildren%
i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
return Children.MaxIndex()?Children:
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}

Autohotkey: Paste/write a simple line of text with a keyboard shortcut?

This is a super simple thing I am trying to get my head around
I want to use something like WINKEY + ALT + C to paste ** - words** so that I can sign-off my posts or whatever using the three-key combo
Not sure what exactly you want, maybe something like this?
Press WINKEY + ALT + C to paste the clipboard contents:
#!c::
SendInput, ^v
Return
Press WINKEY + ALT + C to paste "Some random text"
#!c::
SendInput, Some random text
Return
Instead of Sendinput which will type each characters you can use a clipboard paste approach. See for example https://github.com/tdalon/ahk/blob/59a8ab2a8fd497b4a5b5a85e73e32ff95d5d4425/Lib/Clip.ahk
Clip_Paste(sText,restore := True) {
; Syntax: Clip_Paste(sText,restore := True)
If (restore)
ClipBackup:= ClipboardAll
Clipboard := sText
WinClip.Paste()
If (restore)
Clip_Restore(ClipBackup)
} ; eofun
; ---------------------------------------------------------------------------
Clip_Restore(ClipBackup) {
Clip_Wait() ; in order not to overwrite running clipboard action like pasting
Clipboard:= ClipBackup
} ;eofun
; ---------------------------------------------------------------------------
Clip_Wait(){
Sleep, 150
while DllCall("user32\GetOpenClipboardWindow", "Ptr")
Sleep, -1
} ; eofun

Alt + Space + key in autohotkey

How can I create an Alt + Space + C shortcut in autohotkey? Alt + Space is !space but I don't see how I can add a third key without getting an error.
You can use the #If directive (requires AHK_L) in combination with the GetKeyState() function:
#If GetKeyState("Alt", "p")
Space & c::Traytip,, % a_thishotkey
#If
or you can use the Keywait command:
!space::
keywait, c, d, t0.6
If ErrorLevel
Traytip,, Alt and space
Else
Traytip,, Alt space and c
Return
This will also trigger an Alt+space outcome after 0.6 seconds if you don't press C.
If that is undesirable you can write it like this:
!space::
keywait, c, d, t0.6
If (!ErrorLevel) {
Traytip,, Alt space and c
Sleep, 2000
Traytip,, % a_thishotkey
} Return
!ErrorLevel means "not ErrorLevel"

AutoHotkey Script to send pound (£) on double press of Shift+3

I'm trying to make a script that sends a pound instead of a dollar when you hold down Shift and press 4 twice quickly.
Has anyone seen any code that does this sort of thing?
EDIT:
Okay I've seen some documentation and managed to get it detecting the double shift+3 press like this:
Shift & 4::
if (A_PriorHotkey <> "Shift & 4" or A_TimeSincePriorHotkey > 400)
{
KeyWait, 4
return
}
Send, £
return
But can't get it to send the $ for some reason. Any ideas?
I got the intended functionality working eventually:
Shift & 4::
if (A_PriorHotkey <> "Shift & 4" or A_TimeSincePriorHotkey > 800)
{
Send, {$}
return
}
Send, {BS}
Send, £
return
Basically, when you press Shift+4 the dollar is printed. If you're still holding shift and you press 4 again, the backspace key is pressed and the £ is printed.
As in http://www.autohotkey.com/docs/KeyList.htm#SpecialKeys, you should put key name into " ".
KeyWait, "3"
Does this work?
Shift & 4::
KeyWait, 4 ; waits for '4' to be released
KeyWait, 4, D T.4 ; waits 400ms for 4 to be pressed again
Send % ErrorLevel ? "{$}" : "{BS}{£}"
; if ErrorLevel=1 (4 not pressed) will send $ else will send {BS}£
return
I used to do this in a complicated way as well until I realized that the solution is very simple:
:*:$$::£
Just press $ sign twice to get a £ (or €)
B.t.w. I did the same for ", just press ' twice to get "
:?*:''::"{Space}
The {space} is required for me because " is only printed after I press space. (Dutch language setting).