I have two functions below. They work by themselves but i can't get them to work in the same script. The one at the bottom won't work. Can someone help me to fix. For example, below "LShift & RShift" or "RShift & LShift" won't work. I'm not sure what i'm doing wrong.
endKeys := "{BS}{Enter}{Insert}{Home}{Pgup}{PdDwn}End}{Delete}"
. "{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}"
. "{LShift}{RShift}{Tab}{Esc}{CAPSLOCK}{Ctrl}{PrintScreen}{NumLock}"
. "{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}"
. "{Numpad7}{Numpad8}{Numpad9}{NumpadDel}{Up}{Down}{Left}{Right}"
. "{LAlt}{RAlt}{.}{,}{/}"
~Alt Up::
Input, key, V L1 t0.5 E, % endKeys
If (Errorlevel ~= "Alt") {
Double_ALT := true
Sleep 2000
Double_ALT := false
}
return
; Press a key within two seconds after double tapping the Alt key, to activate an action:
#If (Double_ALT)
a:: MsgBox, Test
b:: MsgBox, Test
c:: MsgBox, Test
d::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
Double_ALT :=false
return
s:: MsgBox, Test
f:: MsgBox, Test
return
LShift & RShift::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
return
RShift & LShift::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
return
endKeys := "{BS}{Enter}{Insert}{Home}{Pgup}{PdDwn}End}{Delete}"
. "{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}"
. "{LShift}{RShift}{Tab}{Esc}{CAPSLOCK}{Ctrl}{PrintScreen}{NumLock}"
. "{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}"
. "{Numpad7}{Numpad8}{Numpad9}{NumpadDel}{Up}{Down}{Left}{Right}"
. "{LAlt}{RAlt}{.}{,}{/}"
~Alt Up::
Input, key, V L1 t0.5 E, % endKeys
If (Errorlevel ~= "Alt") {
Double_ALT := true
Sleep 2000
Double_ALT := false
}
return
; Press a key within two seconds after double tapping the Alt key, to activate an action:
#If (Double_ALT)
a:: MsgBox, Test
b:: MsgBox, Test
c:: MsgBox, Test
d::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
Double_ALT :=false
return
s:: MsgBox, Test
f:: MsgBox, Test
; return <-- likely your problem.
; #IF <-- Use this if you don't want your hotkeys below effected by the IF Directive
LShift & RShift::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
return
RShift & LShift::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
return
Related
folks,
I want to create a layer based keyboard using AutoHotkey. Basicly, I want to achieve what shift already does: modify each key when a modifier is used.
I want to improve regular shift in the following:
press modifier once: only change layer for next character
hold modifier: change layer as long as modifier is down
press modifier twice: enter layer mode, like capslock. (end by another press)
Modifiers: LAlt, RAlt, LControl, RControl (CapsLock, Shift)
How cas I accomplish this?
what I found so far on stackoverflow:
This code allows for shift to be pressed and released for the next character
$*LShift::
SendInput, {LShift Down} ; press shift
Input, Key, L1 M V ; wait for input character
If GetKeyState("LShift", "P") ; if shift still pressed, wait for release
KeyWait, LShift
SendInput, {LShift Up} ; send input with shift down, the shift up
Return
this code turns a double shift press into CapsLock
LShift::
KeyWait, CapsLock ; wait to be released
KeyWait, CapsLock, D T0.2 ; and pressed again within 0.2 seconds
if ErrorLevel
return
else if (A_PriorKey = "CapsLock")
SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"
return
#If, GetKeyState("CapsLock", "P") ; hotkeys go below
a::b
#If
But I am not experienced enough with AHK to bring this together. My goal is to have something like
Modifier::
; code that makes the modifier behave like expected: single press, hold, double press
Return
#If, GetKeyState("Modifier", "P") ; List of key remaps in specific layer
#If
I hope this is specific enough and that you can help me out here.
thanks!
Assign the corresponding Booleam values (true or false) to the variables "Double_LAlt" and "Double_LAlt_holding" in order to create context-sensitive hotkeys depended on their values:
LAlt::
ToolTip,,,, 3
ToolTip,,,, 4
Double_LAlt := false
; Press twice or press twice and hold LAlt within 0,2 seconds
If (A_PriorHotKey = "~LAlt Up" AND A_TimeSincePriorHotkey < 200)
{
Sleep, 200
If GetKeyState("LAlt","P")
{
ToolTip,,,, 4
ToolTip, Double_LAlt_holding,,, 2
Double_LAlt_holding := true
}
else
{
ToolTip,,,, 4
ToolTip, Double_LAlt,,, 3
Double_LAlt := true
}
}
If !((Double_LAlt_holding) || (Double_LAlt)) ; "!" means "NOT" and "||" means "OR"
ToolTip, LAlt_holding,,, 1
return
~LAlt Up::
ToolTip,,,, 1
ToolTip,,,, 2
Double_LAlt_holding := false
Sleep, 100
If (A_TimeIdlePhysical > 100)
Tooltip, PriorHotKey = LAlt Up,,, 4
SetTimer, RemoveTooltip, 1000
return
#If (Double_LAlt_holding) ; If this variable has the value "true"
<!a:: MsgBox, a while Double_LAlt_holding ; "<!" means "LAlt"
<!1:: MsgBox, 1 while Double_LAlt_holding
#If (Double_LAlt)
a:: MsgBox, a after Double_LAlt
1:: MsgBox, 1 after Double_LAlt
; Press a key within 2 seconds after releasing LAlt:
#If (A_PriorHotKey = "~LAlt Up" AND A_TimeSincePriorHotkey < 2000)
a:: MsgBox, a after LAlt Up
1:: MsgBox, 1 after LAlt Up
#If GetKeyState("LAlt","P")
a:: MsgBox, a while LAlt_holding
1:: MsgBox, 1 while LAlt_holding
#If
RemoveTooltip:
If (A_TimeSincePriorHotkey > 2000) ; 2 seconds
ToolTip,,,, 4
return
I'm trying to complete an autohotkey script where you can double tap any SHIFT key twice and follow it by a certain letter to activate a macro.
I have the following script but i have two "bugs" i can't figure out how to solve. I've tried other forums with no luck. Hoping someone can help me out.
I'm a little new at this.
Bug 1: The macro is activated if you press any letter in between the two SHIFTs where it should only be activated if you press the SHIFTs exclusively. For example, pressing SHIFT, s, SHIFT, d will enable the macro.
Bug 2: I'm not sure how this happens but with the following code, I periodically get all or some of the macros to activate while i'm typing. It seems to happen when I type the first capital letter in a sentence. But only sometimes. For example... "bla bla bla profiles. S"
I've fooled around with the timeouts but that doesn't seem to make much of a difference. Any help is appreciated.
Thanks,
Jeff.
~Shift Up::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 400)
{
Double_SHIFT := true
Sleep, 2000
Double_SHIFT := false
}
return
; Press a key within two seconds after double tapping the Shift key, to activate an action:
#If (Double_SHIFT)
d::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
Double_SHIFT :=false
return
a:: MsgBox, Test
s:: MsgBox, Test
f:: MsgBox, Test
return
Fix for Bug 1:
endKeys := "{BS}{Enter}{Insert}{Home}{Pgup}{PdDwn}End}{Delete}"
. "{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}"
. "{LShift}{RShift}{Tab}{Esc}{CAPSLOCK}{Ctrl}{PrintScreen}{NumLock}"
. "{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}"
. "{Numpad7}{Numpad8}{Numpad9}{NumpadDel}{Up}{Down}{Left}{Right}"
. "{LAlt}{RAlt}{.}{,}{/}"
~Alt Up::
Input, key, V L1 t0.5 E, % endKeys
If (Errorlevel ~= "Alt") {
Double_ALT := true
Sleep 2000
Double_ALT := false
}
return
; Press a key within two seconds after double tapping the Alt key, to activate an action:
#If (Double_ALT)
d::
FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
Double_ALT :=false
return
a:: MsgBox, Test
s:: MsgBox, Test
f:: MsgBox, Test
return
I am struggling with a script that monitors selections by mouse in FireFox, Adobe Acrobat and one more program and then copies this selection to clipboard and changes it according to a regex. For each program another regex is needed. Each script works as a separate program, but when I merge them, the copied text is not changed according to my regex.
Script for Adobe Acrobat:
#ifWinActive ahk_class AcrobatSDIWindow
~LButton::
now := A_TickCount
while GetKeyState("LButton", "P")
continue
if (A_TickCount-now > 600 )
{
Send ^c
copied := true
}
return
OnClipboardChange:
if !copied
return
copied := false
ToolTip % Clipboard := RegExReplace(Clipboard, "\r\n", " ")
SetTimer, ToolTipOff, -1000
return
ToolTipOff:
ToolTip
return
And stript for Firefox:
#ifWinActive ahk_class MozillaWindowClass
~LButton::
now := A_TickCount
while GetKeyState("LButton", "P")
continue
if (A_TickCount-now > 600 )
{
Send ^c
copied := true
}
return
OnClipboardChange2:
if !copied
return
copied := false
ToolTip % Clipboard := RegExReplace(Clipboard, "[0-9]\.\s*|\s?\([^)]*\)|\.")
SetTimer, ToolTipOff1, -1000
return
ToolTipOff1:
ToolTip
return
The #If does only work on hotkeys, not on labels. Using OnClipboardChange seems unnecessary. When you press ctrl+c you already know that the clipboard changed.
I also really recommend setting indentations for hotkeys and also #If statements.
Here is how I would do it:
#If WinActive("ahk_class AcrobatSDIWindow") || WinActive("ahk_class MozillaWindowClass")
~LButton::
now := A_TickCount
while GetKeyState("LButton", "P")
continue
if (A_TickCount-now > 600 )
{
Send ^c
if WinActive("ahk_class AcrobatSDIWindow")
{
regex := "\r\n"
replace := " "
}
else if WinActive("ahk_class MozillaWindowClass")
{
regex := "[0-9]\.\s*|\s?\([^)]*\)|\."
replace := ""
}
ToolTip % Clipboard := RegExReplace(Clipboard, regex, replace)
SetTimer, ToolTipOff, -1000
}
return
#If
ToolTipOff:
ToolTip
return
(untested)
edit:
.....
~Left::
~Right::
~Up::
~Down::
now := A_TickCount
while GetKeyState("Shift", "P")
continue
if (A_TickCount-now > 600 )
{
oldShiftState := GetKeyState("Shift", "P")
Send, {Shift Up}
Send ^c
If (oldShiftState)
Send, {Shift Down}
.....
(untested)
I want to have two hotkeys in my script. Namely LWin Up and LWin+LAlt Up. I've tried to do it like that:
LAlt & LWin Up:: ;I've also tried commenting out the first
LWin & LAlt Up:: ;or the second line
LWin Up::
msgbox, % A_ThisHotkey
return
But the output depends on the order in which keys were pressed and released. The time between releasing the first and the second key also affects the result. Sometimes I get two MessageBoxes, sometimes just one and sometimes even none at all (the first line is commented out, press alt, press win, release win, release alt). How do I make it work? To be clear: I want to get only one MessageBox.
In the answer it would be great to see a script that provides full information about the hotkey pressed and the order in which the keys it consist of were pressed and released. *Only one hotkey should be triggered after releasing a hotkey+key combo.
You can not put them altogether.
you should use something like this:
altPressed := false
LAlt & LWin Up::
msgbox, % A_ThisHotkey
return
LWin & LAlt Up::
msgbox, % A_ThisHotkey
altPressed := true
return
LWin Up::
if !altPressed {
msgbox, % A_ThisHotkey
}
altPressed := false
return
If what you want to do instead of msgbox is too spreaded in my code you can use the below one:
SetTimer, toDo, 10
toDo:
if doWhatEver {
;; HERE DESCRIBE WHAT TO DO
doWhatEver := false
}
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
altPressed := false
doWhatEver := false
LAlt & LWin Up::
doWhatEver := true
return
LWin & LAlt Up::
doWhatEver := true
altPressed := true
return
LWin Up::
if !altPressed {
doWhatEver := true
}
altPressed := false
return
TechJS's answer wasn't working exactly as I wish so here is my script. It detects the order in which the keys were pressed and released, and doesn't depend on time between keys pressed/released.
global firstPressed := ""
LAlt::
altDown := true
if (winDown)
return
firstPressed := "!"
return
LWin::
winDown := true
if (altDown)
return
firstPressed := "#"
return
LAlt Up::
altDown := false
if (!winDown) {
if (comboJustUp) {
comboJustUp := false
return
}
msgbox !
}
if (winDown) {
comboJustUp := true
if (firstPressed = "#")
msgbox #!!.
if (firstPressed = "!")
msgbox !#!.
}
return
LWin Up::
winDown := false
if (!altDown) {
if (comboJustUp) {
comboJustUp := false
return
}
msgbox #
}
if (altDown) {
comboJustUp := true
if (firstPressed = "!") ; \here is one bug though. If you switch theese
msgbox !##. ; /two lines
if (firstPressed = "#") ; \with theese
msgbox #!#. ; /two. It won't work correctly for some reason
}
return
I'm trying to re-map the arrow keys to a combination of Alt-key to get them more centered on the keyboard. The problem is that I cant get the combination with shift to work (for selecting text while moving the cursor).
This is a starting point:
lalt & ö:: Send, {left}
lalt & å:: Send, {up}
lalt & -:: Send, {down}
lalt & ä:: Send, {right}
Any tips would be appreciated.
This only fixes it for Shift.
lalt & ö::
If GetKeyState("Shift", "D") = true
Send, +{Left}
Else
Send, {Left}
Return
lalt & å::
If GetKeyState("Shift", "D") = true
Send, +{Up}
Else
Send, {Up}
Return
lalt & -::
If GetKeyState("Shift", "D") = true
Send, +{Down}
Else
Send, {Down}
Return
lalt & ä::
If GetKeyState("Shift", "D") = true
Send, +{Right}
Else
Send, {Right}
Return
You can declare alt modifier with ! and shift with +
Combine them to give alt + shift
!ö:: Send, {left}
!å:: Send, {up}
!-:: Send, {down}
!ä:: Send, {right}
+!ö:: Send, +{left}
+!å:: Send, +{up}
+!-:: Send, +{down}
+!ä:: Send, +{right}