AHK Trouble getting my image to show when pressing GUI - autohotkey

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

Related

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.

Input text on any application with autohotkey gui

I'm trying to find a solution to add predefined text to any application so instead of remembering a hotkey/hotstring combination I'll just need to click on the GUI button for the text.
This is what I have right now:
Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
; Generated using SmartGUI Creator 4.0
Gui, Show, x152 y89 h131 w222, New GUI Window
Return
ButtonTitle:
Send Title
return
ButtonParagraph:
Send Paragraph
return
GuiClose:
ExitApp
My problem is that I'm not able to make it work properly. I just want to click the button and that word gets shot to the notepad/word/any application.
The solution would be to always keep track of the current and the last active window. To achieve that you could use a shell hook to get notified when the active window changes: https://autohotkey.com/board/topic/66726-method-to-detect-active-window-change/
So you could have two variables currentWin and lastWin and when the active window changes you set lastWin := currentWin and currentWin := activeWin.
Soemthing like this maybe:
Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
; Generated using SmartGUI Creator 4.0
Gui, Show, x152 y89 h131 w222, New GUI Window
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
ShellMessage(wParam, lParam) {
If (wParam=4) { ;HSHELL_WINDOWACTIVATED
lastWin := currentWin
currentWin := "ahk_id " . lParam
}
}
ButtonTitle:
WinActivate, % lastWin
Send Title
return
ButtonParagraph:
WinActivate, % lastWin
Send Paragraph
return
GuiClose:
ExitApp
(completely untested)
Hi Stephan and Forivin,
Thank you for your help. I used the alt+tab approach to solve the problem though I need to ensure that I get notepad on alt+tab keystroke or else it goes to another application. The below solves the problem.
Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
Gui, Show, x152 y89 h131 w222, New GUI Window
Return
ButtonTitle:
Send, !{Esc}
Send Title
return
ButtonParagraph:
Send, !{Esc}
Send Paragraph
return
GuiClose:
ExitApp

Can't get clipboard printed to GUI to update on 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

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.