Can't get clipboard printed to GUI to update on autohotkey - autohotkey

So I can't seem to get it to change, it's supposed to print out whatever I have copied to my clipboard onto the gui. but I can't seem to get it to update
b = 0
Gui, New, +Resize -MaximizeBox, Farming
Gui, Color, EEAA99
Gui +LastFound
WinSet, TransColor, EEAA99(True)
Gui, Farming:+AlwaysOnTop +Disabled -SysMenu +Owner
while(True)
{
new1 = %clipboard%
if(b == 0)
{
Gui, Farming:Add, Text, Vkek, Current copied: %new1%
Gui, Farming:Show, AutoSize Center
clips = %new1%
b = 1
}
if(%new1% <> %clips%)
{
b = 0
}
}

change if(%new1% <> %clips%) to if(new1 <> clips). You can read about comparing variables in the documentation here:
https://autohotkey.com/docs/Variables.htm#Expressions
Once that is fixed you are going to have another issue in that you will be trying to add a new text control to your gui with the same variable as an existing control (kek). Instead, you need to change the content of the text control using GuiControl command:
https://autohotkey.com/docs/commands/GuiControl.htm

Related

AHK Trouble getting my image to show when pressing GUI

I've been editing a code to make it more personal and can't seem to get the %crsLocation% image to open with it. The button presses, but nothing else happens. I have tried directly connecting the directory to no prevail. I'm not sure what else to do. I am still kinda new to AHK and besides some basic classes in college and Codecademy my knowledge is still limited.
I was wondering if anyone could see what I am doing wrong
#NoEnv
#SingleInstance Force
SetBatchLines, -1
SetWorkingDir, A_ScriptDir
; GUI Design
Gui Show, x600 y325 w481 h381, CrossHair Overlay
Gui, Color, Gray
Gui, Font, Caqua
; GUI Buttons
Gui Add, Button, vCrosshair gCrosshair Default w80, Crosshair
Gui Add, Button, vReload gReload Default w80, Reload
Gui Add, Button, vExit gExit Default w80, Exit
Return
; Labels
Reload:
Reload
return
Exit:
ExitApp
return
Crosshair:
If _Crosshair := ! _Crosshair
Loop
{
;Config
crsLocation := "crosshairdot.png"
crsHeight := "7"
crsWidth := "7"
invsColor := "ffffff"
locCompensator := "4"
locX := "960"
loxY := "540"
;End of config
diflocX := locX - locCompensator
diflocY := locY - locCompensator
setCross = 0
~XButton2::
if (setCross = 0) {
Gui, chscript: New
Gui, Add, Picture, x0 y0 h%crsHeight% w%crsWidth%, %crsLocation%
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x00000020
Gui, Show, x%diflocX% y%diflocY% h%crsHeight% w%crsWidth%
; Middle of Screen = 960 540
Gui, Color, %invsColor%
WinSet, TransColor, %invsColor%
setCross = 1;
}
else {
Gui, chscript: Destroy
setCross = 0
}
Return
}
Return
Return
First of all in the documents it states scriptdir with percents around it, even though it works without signs I'd stick with docs suggestions,
SetWorkingDir, %A_ScriptDir%
and then there is this typo,
loxY := "540"
should be locY I belive

Autohotkey - How to navigate a radio list using up and down arrow keys?

I have the following script. I'm not sure how I can modify it to navigate the results using the up or down arrow keys. To run it, just create a .txt file and add some words in there (one word per line), then edit the filepath to where your .txt file is located. Then just search for a keyword that is found in at least 2 of the lines. e.g
Word1
Word2
If you search for word, it will return both word1 and word2. Then I just need to choose between them using up and down arrow key.
F9::
{
FilePath := "D:\5. Programs\AutoHotkey L x64\test.txt"
Gui, Destroy
Gui, Font, S20
Gui, Add, Text, X25 Y10 W450 H30 +Center , Search Box
Gui, Font, S10
Gui, Add, Edit, XP Y+20 W450 H20 vSearchString,
Gui, Color
Gui, Show, W500 H100, Search Box
return
#IfWinActive, Search Box
{
Enter::
Gui, Submit, NoHide
ResultList := []
ChosenString := ""
Loop, Read, %FilePath%
{
if (InStr(A_LoopReadLine, SearchString))
{
ResultList.Push(A_LoopReadLine)
}
}
if (!ResultList.Length())
{
;MsgBox % "No match found!"
return
}
Gui, DisplayResults:New,-MaximizeBox -MinimizeBox , Search results
Gui, Add, Text, w250, % "Click on one of the results below:"
for key, value in ResultList
{
if (key = 1)
Gui, Add, Radio, gSelectResult vChosenString, %value%
else
Gui, Add, Radio, gSelectResult, %value%
}
Gui, DisplayResults:Show
return
SelectResult:
Gui, DisplayResults:Submit
;Msgbox, % ResultList[ChosenString]
Clipboard := % ResultList[ChosenString]
return
}
}
return
You don't want the GUI to disappear?
Add NoHide in line number 44 like this:
Gui, DisplayResults:Submit, NoHide.

Button automatically activating

I'm not quite sure why, but whenever I run the ahk file the button automatically activates. (I put the GuiClose: ExitApp so that it doesn't infinitely refresh). Also, is there a better way to do this?
#Persistent
#SingleInstance, force
ontop = 1
Gui, -Caption
Gui, Font,cPurple s10, Arial Bold
Gui, Add, Picture, x0 y0 gUImove, bg-1.jpg
Gui, Add, Picture, x0 y40, bg-1.jpg
If ontop = 1
{
Gui, +AlwaysOnTop
}
Gui, Add, Text, x190 y0 +BackgroundTrans,test
Gui, Add, Button, x100 y200 w120 h40 , disableOnTop
Gui, Show, w500 h340
TrayTip , Title, test, 20
UImove:
GuiClose:
ExitApp
disableOnTop:
{
If ontop = 0
{
ontop = 1
Reload
Sleep 5000
Return
}
Else If ontop = 1
{
ontop = 1
Reload
Sleep 5000
Return
}
}
Return
If you want the code following the disableOnTop label to run when clicking the GUI button, you need to put its name in the options of the button following a letter "g", like so:
Gui, Add, Button, x100 y200 w120 h40 gdisableOnTop , Click me
For proper functionality, you'll also need to put a Return after Gui, Show.
Note that variables are not saved when you reload. Also, note that the Sleep 5000 and Return are after Reload, which means it won't be executed. (Unless it can't reload, such as if there is a syntax error.)
I'm surprised that it's running your button code at all; it looks like it should run into ExitApp and all you'd see is a brief flash of the GUI before it exits.

Window transparency changing affecting active windows

I have a code for hiding a window with AutoHotKey:
NumpadEnter::
Trans:=255
Loop
{
WinSet, Transparent, %Trans%, A
Sleep, 20
Trans-=1
if(Trans <= 0)
Break
}
return
Works like a charm, but you can see that execution time of this function is about 4-5 seconds. I can't switch between other windows in these 4-5 seconds, because other windows will be affected with WinSet function.
I need to save window handle to variable before the loop. And use it on the line with WinSet function.
How can I do that?
One way is to use the winexist() function with the A option as the wintittle parameter, that will give you the ID of the active window so that you can use that.
Something like this
NumpadEnter::
hWnd := WinExist("A")
Trans:=255
Loop
{
WinSet, Transparent, %Trans%, Ahk_id %hWnd%
Sleep, 20
Trans-=1
if(Trans <= 0)
Break
}
return
Hope it helps
Edit:
The full documentation: http://www.autohotkey.com/board/topic/80577-how-to-animate-a-gui-window/
Edit 2:
You mentioned it didn't work for you. Here is a working example on Windows 8 machine using Ahk_L (aka. Autohotkey_L or Autohotkey_Lexiko):
DetectHiddenWindows, On ;//Allow hidden windows to be detectable
SetWinDelay, -1 ;//Make Window update very fast (smooth animation)
FADE := 524288
SHOW := 131072
HIDE := 65536
FADE_SHOW := FADE+SHOW
FADE_HIDE := FADE+HIDE
SetFormat, Integer, Hex
FADE_SHOW+=0 ;//Converts to 0xa0000
FADE_HIDE+=0 ;//Converts to 0x90000
SetFormat, Integer, d
Gui, Font, w500 s35 Center, Verdana
Gui, Add, Text, , Hello! This Window will hide in 5 Seconds.
Gui, Show, NA Hide, Test Window ; //Create the Window hidden
Gui, +LastFound
GUI_ID := WinExist() ;//Get Window ID
Duration := 3000 ;//Speed of Window showing/hiding
DllCall("AnimateWindow","UInt",GUI_ID,"Int",Duration,"UInt", FADE_SHOW) ;//Fade in Window
Sleep, 5000 ;//Pause for 5 seconds
DllCall("AnimateWindow","UInt",GUI_ID,"Int",Duration,"UInt", FADE_HIDE) ;//Fade out Window
Return

Steam Utility Menu Autohotkey

I have looked thoroughly around the interwebs for this, but I was wondering if anyone had a way that I could remap Shift + Tab so that it brings up a context menu like you see in steam. This would have a transparent background, and no window icon. And just like the steam menu, I want it to have stuff that would be useful. I have tried to do this on my own, but I was not successful. Anyone have any ideas?
I feel like this is much more complicated than you make it out to be.
Here is some code to get the fade effect without a window icon. Use Shift+Tab.
#SingleInstance force
#NoTrayIcon
SetBatchLines, -1
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79
Transparency := 0
Fade := 0
Settimer, GUI2AlwaysOnTop, 10 ; Keep gui 2 on top
Gui, 1: Default
Gui, Color, 0x000000 ; Color to black
Gui, +LastFound +AlwaysOnTop -Caption +E0x20 ; Click through GUI always on top.
Gui, 1: +owner
WinSet, Transparent, %Transparency%
Gui, Show, x0 y0 w%VirtualWidth% h%VirtualHeight% ; Cover entire screen, may have to adjust X if you have multiple monitors
Return
Shift & Tab::
If (Fade:=!Fade)
FadeIn(500, 40)
Else
FadeOut(500)
Return
FadeIn(TotalTime = 500, TransFinal = 255)
{
StartTime := A_TickCount
Loop
{
Transparency := Round(((A_TickCount-StartTime)/TotalTime)*TransFinal)
WinSet, Transparent, %Transparency%, ahk_class AutoHotkeyGUI
if (Transparency >= TransFinal)
break
Sleep, 10
}
}
FadeOut(TotalTime = 500)
{
StartTime := A_TickCount
Loop
{
Transparency := ((TimeElapsed := A_TickCount-StartTime) < TotalTime) ? 100*(1-(TimeElapsed/TotalTime)) : 0
WinSet, Transparent, %Transparency%, ahk_class AutoHotkeyGUI
if (Transparency = 0)
break
Sleep, 10
}
}
GUI2AlwaysOnTop:
Gui, 2: +AlwaysonTop
return
A good amount of the GUI code is from SmartBright. I've had these fade functions around, I know I modified someone else's script to my liking, but I cannot find the source.