Double tap SHIFT key followed by a letter - autohotkey

I would like to be able to double tap a SHIFT key followed by a letter to activate an action. Can anyone help? It would be nice to be able to double tap either SHIFT key.
Something like??
<+<+ or >+>+ then d
do something
return
~Shift Up::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 500)
{
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)
a:: MsgBox, This macro has not yet been enabled. Contact IT for suggestions.
b:: FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
c:: MsgBox, This macro has not yet been enabled. Contact IT for suggestions.
return

~Shift Up::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 500)
{
Double_SHIFT := true
ToolTip, Double_SHIFT ; remove this line, if you don't want a tooltip displayed
Sleep, 2000
Double_SHIFT := false
ToolTip ; remove this line, if you don't want a tooltip displayed
}
return
; Press a key within two seconds after double tapping the Shift key, to activate an action:
#If (Double_SHIFT)
a:: MsgBox, Double_SHIFT + a
b:: MsgBox, Double_SHIFT + b
#If

Displays message box when shiftshiftd pressed
~LShift::ShiftPressed()
~RShift::ShiftPressed()
$d::DPressed()
ShiftPressed()
{
global t1,t2
t1 := t2
t2 := A_TickCount
}
DPressed()
{
global t1,t2
if (A_TickCount < t1 + 1000) && (A_TickCount < t2 + 1000)
MsgBox Shift Shift D Pressed
else
sendinput d
}

Related

How to reset a key sequence with a specific key?

So this sequence resets itself after 1.5 sec (t:=1500) which means if i dont hit the left mouse button for 1.5 sec it always sends A. Otherwise it sends the next letter after each click.
I want to further tweak this code with another function which is to be able to reset the sequence with right mouse button too. So if i hit RButton any time it should reset to A.
Thx.
global s:=0, c:=0, t:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
Seqkeys(params*) {
global s, c, t
max := params.MaxIndex()
(A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1
s := A_TickCount
return params[c]
}
Merely reset the current key index 'c', and the last clicked time 's':
*RButton::
c := 1
s := 0
return
I think your script would benefit with more meaningful variable names:
global lastClickedTime:=0, currentKeyIndex:=0, clickThreshold:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
*RButton::
currentKeyIndex := 1
clickThreshold := 0
return
Seqkeys(params*) {
global lastClickedTime, currentKeyIndex, clickThreshold
max := params.MaxIndex()
currentKeyIndex += 1
if((A_TickCount - lastClickedTime) <= clickThreshold && currentKeyIndex <= max) {
; Do nothing
} else {
currentKeyIndex := 1
}
lastClickedTime := A_TickCount
return params[currentKeyIndex]
}

Detect F key press after holding right mouse button

I am trying to write a script that detects Right Mouse Click being held for at least 1.5 seconds and then the F key being pressed down while Right Mouse Click is still being held.
I tried the following:
Loop
{
Send, {F Down}
Sleep 2000
Send, {F Up}
sleep 1500
}
return
^F::Pause
I realized this is only a timer and does not detect which keys were pressed. How do I write a script that achieves functionality described above?
loop
{
Key := GetKeyState("rbutton")
while(Key = 0)
{
Key := GetKeyState("rbutton")
sleep,100
}
while(Key = 1)
{
sleep,100
loopnmb := A_Index
if(loopnmb = 8) ;;this number changes the length rbutton has to be pressed before F key activates
{
Key := GetKeyState("rbutton")
while(Key = 1)
{
Send, {F Down}
Key := GetKeyState("rbutton")
if(Key = 0)
{
Send, {F Up}
break
}
}
}
}
}
Timer is a little bit off so play around with it.

AutoHotKey: move to next program when press a key

For example, I have Notepad, Word, and Chrome open. How do I write the script in AutoHotKey such that when I press the F9 key on the keyboard, it will move to the next application?
Try:
AltTab_ID_List_ := []
setTimer, updateList, 100
+f9::WinActivate, % "AHK_ID" AltTab_ID_List_[(pointer == 1 or pointer == 0
? AltTab_ID_List_.Count()-1 : --pointer)]
f9::WinActivate, % "AHK_ID" AltTab_ID_List_[++pointer]
updateList:
list := AltTab_window_list()
if (AltTab_ID_List_.MaxIndex() != list.MaxIndex())
AltTab_ID_List_ := list
cur:=WinExist("A")
for e, v in AltTab_ID_List_
if (cur == v)
pointer := AltTab_ID_List_.MaxIndex() == e ? 0 : e, break
return
AltTab_window_list()
{
WS_EX_CONTROLPARENT =0x10000
WS_EX_APPWINDOW =0x40000
WS_EX_TOOLWINDOW =0x80
WS_DISABLED =0x8000000
WS_POPUP =0x80000000
AltTab_ID_List_ := [] ;AltTab_ID_List_ =0
WinGet, Window_List, List ; Gather a list of running programs
id_list =
Loop, %Window_List%
{
wid := Window_List%A_Index%
WinGetTitle, wid_Title, ahk_id %wid%
WinGet, Style, Style, ahk_id %wid%
If ((Style & WS_DISABLED) or ! (wid_Title)) ; skip unimportant windows ; ! wid_Title or
Continue
WinGet, es, ExStyle, ahk_id %wid%
Parent := Decimal_to_Hex( DllCall( "GetParent", "uint", wid ) )
WinGetClass, Win_Class, ahk_id %wid%
WinGet, Style_parent, Style, ahk_id %Parent%
If ((es & WS_EX_TOOLWINDOW)
or ((es & ws_ex_controlparent) and ! (Style & WS_POPUP) and !(Win_Class ="#32770") and ! (es & WS_EX_APPWINDOW)) ; pspad child window excluded
or ((Style & WS_POPUP) and (Parent) and ((Style_parent & WS_DISABLED) =0))) ; notepad find window excluded ; note - some windows result in blank value so must test for zero instead of using NOT operator!
continue
AltTab_ID_List_.push(wid)
}
return AltTab_ID_List_
}
Decimal_to_Hex(var)
{
SetFormat, integer, hex
var += 0
SetFormat, integer, d
return var
}
I changed the "errorseven" code for better performance (removing the update timer from the list) and usability
!WheelDown::
gosub UpdateWindowsList
Item_ID_List.Push(Item_ID_List.RemoveAt(1))
gosub PrintList
WinActivate, % "AHK_ID" Item_ID_List[1]
return
!WheelUp::
gosub UpdateWindowsList
Item_ID_List.InsertAt(1, Item_ID_List.Pop())
gosub PrintList
WinActivate, % "AHK_ID" Item_ID_List[1]
return
; Update list order
!MButton::
Item_ID_List := Get_Windows_List()
return
UpdateWindowsList:
New_Item_ID_List := Get_Windows_List()
FirstNow := New_Item_ID_List[1]
; Checks if the active program was already on the old list
for index, value in Item_ID_List {
if (value = FirstNow)
break
}
; If the active program is not at the beginning of the list, bring it to the beginning
if (value = New_Item_ID_List[1]) {
while(FirstNow != Item_ID_List[1]) {
RemovedValue := Item_ID_List.RemoveAt(1)
Item_ID_List.Push(RemovedValue)
}
}
; Delete closed items from the old list
TempArray := []
for index, value in Item_ID_List {
for index2, value2 in New_Item_ID_List {
if (value = value2) {
TempArray.push(New_Item_ID_List.RemoveAt(index2))
break
}
}
}
; Updates the old list with new open programs
for index2, value2 in New_Item_ID_List {
TempArray.push(value2)
}
Item_ID_List := TempArray
; If the active program is not at the beginning of the list, bring it to the beginning
while(FirstNow != Item_ID_List[1]) {
RemovedValue := Item_ID_List.RemoveAt(1)
Item_ID_List.Push(RemovedValue)
}
return
Get_Windows_List()
{
WS_EX_CONTROLPARENT =0x10000
WS_EX_APPWINDOW =0x40000
WS_EX_TOOLWINDOW =0x80
WS_DISABLED =0x8000000
WS_POPUP =0x80000000
AltTab_ID_List := [] ;AltTab_ID_List =0
WinGet, Window_List, List ; Gather a List of running programs
id_List =
Loop, %Window_List%
{
wid := Window_List%A_Index%
WinGetTitle, wid_Title, ahk_id %wid%
WinGet, Style, Style, ahk_id %wid%
if ((Style & WS_DISABLED) or ! (wid_Title)) ; skip unimportant windows ; ! wid_Title or
Continue
WinGet, es, ExStyle, ahk_id %wid%
Parent := Decimal_to_Hex( DllCall( "GetParent", "uint", wid ) )
WinGetClass, Win_Class, ahk_id %wid%
WinGet, Style_parent, Style, ahk_id %Parent%
if ((es & WS_EX_TOOLWINDOW)
or ((es & ws_ex_controlparent) and ! (Style & WS_POPUP) and !(Win_Class ="#32770") and ! (es & WS_EX_APPWINDOW)) ; pspad child window excluded
or ((Style & WS_POPUP) and (Parent) and ((Style_parent & WS_DISABLED) =0))) ; notepad find window excluded ; note - some windows result in blank value so must test for zero instead of using NOT operator!
continue
AltTab_ID_List.push(wid)
}
return AltTab_ID_List
}
Decimal_to_Hex(var)
{
Setformat, integer, hex
var += 0
Setformat, integer, d
return var
}
PrintList:
names =
for index, value in Item_ID_List {
WinGetTitle, OutputVar , AHK_ID %value%
frase = % "Item " index " is '" OutputVar "'"
names = %names%%frase%`n
}
ToolTip, %names%
SetTimer, RemoveToolTip, -1000
return
RemoveToolTip:
ToolTip
return

Is Autohotkey able to perform sequential pastes?

Is it possible to create a script for the multiple successive pastes?
Example: I copy ten different words with Ctrl+C (10 times) and paste into my doc pressing Ctrl+V (10 times).
Just for fun:
copiedText := []
~^C::
ClipWait, 0
copiedText.push(clipboard), clipboard := ""
return
^V::sendInput % copiedText.length() ? copiedText.remove(1) : _
something like this
loop,
{
position = 0
loop,
{
~^c::
if (a_index = 9){
position = 0
}
else
{
position := position + 1
}
ClipWait
var%position% := clipboard
return
}
::p1::
send, %var1%
return
::p2::
send, %var2%
return
::p3::
send, %var3%
return
::p4::
send, %var4%
return
::p5::
send, %var5%
return
::p6::
send, %var6%
return
::p7::
send, %var7%
return
::p8::
send, %var8%
return
::p9::
send, %var9%
return
::p10::
send, %var10%
return
}
save clipboard into var then input them where and how you like to.

How to input (Holding LButton)?

I am trying to make (Holding down the left button for 1s) to make it do a right click. Here's what i got:
LButton::
MouseClick, right, , , 1, 0, D
Sleep 0
MouseClick, right, , , 1, 0, U
return
How to change the "LButton" input into "Hold LButton for 1 second"?
How about this...
LButton::
StartTime := A_TickCount ; Set the timer
KeyWait, LButton ; Wait for release of mousebutton
ElapsedTime := A_TickCount - StartTime ; Calculate elapsed time
if (ElapsedTime > 1000)
Click, Right ; when longer than 1000 ms
Click, Left ; when shorter than 1000 ms
return
The disadvantage is that you can't use the mouse for e.g. highlighting text anymore...
Here you go:
#Persistent
#SingleInstance Force
#NoEnv
SetBatchLines, -1
global timeDown = 0
SetTimer, checkLeftClick,25
checkLeftClick:
if( GetKeyState("LButton" , "P") )
{
timeDown += 25
}
else
{
timeDown = 0
}
if(timeDown > 1000)
{
MouseClick , left , , , , ,U
Click,Right
timeDown = 0
}
return