The following code two GUIs that appear in the bottom right and left of your screen. This is perfect for if you have a tablet device and want to study your cards while away from your desk.
The buttons with the Q3 / Q4 are "Quick" keys; essentially pressing space and then the corresponding number.
Code: Select all
;Anki GUI for touch screens
;-------------------------------------------------------------------------
;2021-06-12, Simon's code
;https://autohotkey.com/board/topic/65319-using-the-same-ifwinactive-for-multiple-windows/
;================================================
;at the start of the script (or maybe here), define the variable below
;~ global intAnkiButtonPressCount := 0
;================================================
#SingleInstance, Force
GuiShowFlag := False
EnabledIcon = %A_ScriptDir%\AnkiIcon.png
;Set the icon image
Menu,Tray,Icon, %EnabledIcon%
F1 & F12::
If WinActive ("ahk_class Qt5QWindowIcon")
{
SetTitleMatchMode, 2
if winactive("- Anki") Then
{
If GuiShowFlag = True
{
gui, GuiLeft:hide
gui, GuiRight:hide
GuiShowFlag := False
}
else
{
GuiShowFlag := True
;-------------------------------------------------------------------------
;Find the co-ordinates of the active window
WinGetPos, X, Y, Width, Height, A ; "A" to get the active window's pos.
;-------------------------------------------------------------------------
;Define gui specs - Change these as required
intGuiWidth := 75
intButtonHeight := intGuiWidth - 10
intNumberOfButtons := 8
intGuiHeight := (intButtonHeight + 5)*intNumberOfButtons +5
intOffsetFromBottom := 150
;Set the location of Gui 1
intGui1Height := intGuiHeight + 5
intGui1y := Y + Height - intGui1Height - intOffsetFromBottom - 150
intGui1Width := intGuiWidth
intGui1x := X + 10 ;+ Width - intGui1Width
;Set the location of Gui 2
intGui2Height := intGuiHeight + 5
intGui2y := Y + Height - intGui2Height - intOffsetFromBottom - 150
intGui2Width := intGuiWidth
intGui2x := X + Width - intGui2Width - 55
;Define button dimensions
intButtonWidth := intGuiWidth - 10
intButtonHeight := intGuiWidth - 10
;-------------------------------------------------------------------------
;Define transparency level
intTransparency := 150
;-------------------------------------------------------------------------
;Gui 1 setup
;https://autohotkey.com/board/topic/57707-noactivate-but-clickable/
Gui, 1: +LastFound +AlwaysOnTop +ToolWindow -Caption +E0x08000000
Gui, 1:Color, FFFFFF ;white
;Gui, 1:+AlwaysOnTop
;Gui, 1:+ToolWindow -Caption
Gui, 1:Add, Button, x5 y5 w%intButtonWidth% h%intButtonHeight% gFour_AnswerButton_Anki,4
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gThree_AnswerButton_Anki,3
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gTwo_AnswerButton_Anki,2
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gOne_AnswerButton_Anki, 1
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gUndo_Anki,Undo
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gSuspendCard_Anki, Suspend Card
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gBury_Anki, Bury
Gui, 1:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gResetProgress_Anki, Reset Progress
Gui, 1:Show,x%intGui1x% y%intGui1y% w%intGui1Width% h%intGui1Height% NoActivate, GuiLeft
WinSet, Transparent, %intTransparency%, GuiLeft
;WinSet, AlwaysOnTop, On, Mini Tut 19
;WinSet, Transcolor, 000111, Mini Tut 19
;-------------------------------------------------------------------------
;Gui 2 setup
;https://autohotkey.com/board/topic/57707-noactivate-but-clickable/
Gui, 2: +LastFound +AlwaysOnTop +ToolWindow -Caption +E0x08000000
Gui, 2:Color, FFFFFF ;white
;Gui, 2:+AlwaysOnTop
;Gui, 2:+ToolWindow -Caption
Gui, 2:Add, Button, x5 y5 w%intButtonWidth% h%intButtonHeight% gQuickFour_AnswerButton_Anki,Q4
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gQuickThree_AnswerButton_Anki,Q3
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gQuickTwo_AnswerButton_Anki,Q2
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gBlueFlag_Toggle_Anki, Blue
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gChangeDeck_Anki, Change Deck
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gMegaLibraryAHK, MegaLibary GUI
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gReload_Anki, Reload
Gui, 2:Add, Button, y+5+%intButtonHeight% w%intButtonWidth% h%intButtonHeight% gTaskbar_Toggle_Anki, Show Taskbar
;Gui, Show, NoActivate ; Don't deactivate current window
;If "NoActivate" is to work properly, XMouse needs to be off.
Gui, 2:Show,x%intGui2x% y%intGui2y% w%intGui2Width% h%intGui2Height% NoActivate, GuiRight
WinSet, Transparent, %intTransparency%, GuiRight
;-------------------------------------------------------------------------
return
}
}
else ;If the active window is not Anki
{
ToolTip, %A_ThisHotkey% not relevant for the current window
Sleep 1500
ToolTip
}
}
return
#IfWinActive
^#a::
{
WinGetClass, class, A
MsgBox '%A_ThisHotkey%' is not active for this program (%class%)
return
}
return
;-------------------------------------------------------------
;-------------------------------------------------------------
;=============================================================
;ANKI GUI FUNCTIONS
;=============================================================
;-------------------------------------------------------------
QuickTwo_AnswerButton_Anki()
{
Send, {space}
Sleep, 600
Send, 2
;~ controlsend,, 2
intAnkiButtonPressCount:=0
;fUpdateCSV("'" . A_ThisHotkey . " - Send Space then 2 in Anki'") ;2021-06-11
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
QuickThree_AnswerButton_Anki()
{
Send, {space}
Sleep, 600
Send, 3
;~ controlsend,, 3
intAnkiButtonPressCount:=0
;fUpdateCSV("'" . A_ThisHotkey . " - Send Space then 3 in Anki'") ;2021-06-11
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
QuickFour_AnswerButton_Anki()
{
Send, {space}
Sleep, 600
Send, 4
;~ controlsend,, 4
intAnkiButtonPressCount:=0
;fUpdateCSV("'" . A_ThisHotkey . " - Send Space then 4 in Anki'") ;2021-06-11
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
Bury_Anki()
{
Send, -
intAnkiButtonPressCount:=0
;fUpdateCSV("'" . A_ThisHotkey, " - Send '-' in Anki'") ;2021-06-11
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
Undo_Anki() ;2021-06-13
{
Send, ^z
intAnkiButtonPressCount:=0
;fUpdateCSV("'" . A_ThisHotkey, " - 'Undo' in Anki'") ;2021-06-11
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
One_AnswerButton_Anki()
{
if (intAnkiButtonPressCount < 1) Then
{
intAnkiButtonPressCount++
Send, {space}
}
else
{
Send, 1
intAnkiButtonPressCount:=0
}
;fUpdateCSV("'" . A_ThisHotkey . " - Send 1 in Anki'") ;2021-06-11
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
Two_AnswerButton_Anki()
{
if (intAnkiButtonPressCount < 1) Then
{
intAnkiButtonPressCount++
Send, {space}
}
else
{
Send, 2
intAnkiButtonPressCount:=0
}
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
Three_AnswerButton_Anki()
{
if (intAnkiButtonPressCount < 1) Then
{
intAnkiButtonPressCount++
Send, {space}
}
else
{
Send, 3
intAnkiButtonPressCount:=0
}
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
Four_AnswerButton_Anki()
{
if (intAnkiButtonPressCount < 1) Then
{
intAnkiButtonPressCount++
Send, {space}
}
else
{
Send, 3
intAnkiButtonPressCount:=0
}
}
;-------------------------------------------------------------
;-------------------------------------------------------------
BlueFlag_Toggle_Anki()
{
Send, ^4
}
;-------------------------------------------------------------
;-------------------------------------------------------------
Reload_Anki()
{
Reload
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
ResetProgress_Anki()
{
;browse button
Send, b
;wait for browse window
SetTitleMatchMode, 2
WinWaitActive, Browse (
;press reset ?^!r
Send, ^!r
;~ WAit for the reschedule window
SetTitleMatchMode, 2
WinWaitActive, Reschedule
;Press ok
SetTitleMatchMode, 2
If WinActive("Reschedule") Then
{
Send, {Enter}
}
;Wait for browse window
SetTitleMatchMode, 2
WinWaitActive, Browse (
;press escape
Send, {esc}
intAnkiButtonPressCount:=0
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
Taskbar_Toggle_Anki()
{
Send, #t
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
MegaLibraryAHK()
{
Send, {F13}
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
ChangeDeck_Anki()
{
;browse button
Send, b
;wait for browse window
SetTitleMatchMode, 2
WinWait, Browse (, , 3
if ErrorLevel
{
MsgBox, WinWait timed out.
return
}
;Change deck keyboard shortcut
Send, ^d
;~ WAit for the deck change window
SetTitleMatchMode, 2
WinWait, Change Deck, , 4
if ErrorLevel
{
MsgBox, WinWait timed out.
return
}
;Wait for deck change window to close
SetTitleMatchMode, 2
WinWaitClose, Change Deck
ifWinExist, Browse (
{
Send, {esc}
}
intAnkiButtonPressCount:=0
}
Return
;-------------------------------------------------------------
;-------------------------------------------------------------
SuspendCard_Anki()
{
Send, {@}
intAnkiButtonPressCount:=0
}
Return
;-------------------------------------------------------------