Window transparency changing affecting active windows - autohotkey

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

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

pixelsearch and click right pixel

IF NOT A_IsAdmin ; Runs script as Admin.
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
#MaxThreadsPerHotkey, 2
CoordMode, Pixel, Screen
#singleInstance, Force
toggle = 0
upperLeftX := 750
upperLeftY := 400
lowerRightX := 850
lowerRightY := 500
F8:: ; press F8 to toggle the loop on/off.
SoundBeep
Toggle := !Toggle
While Toggle
{ ;-- Begin of loop.
PixelSearch, X, Y,%upperLeftX%, %upperLeftY%, %lowerRightX%, %lowerRightY%, 0x000000, 0, Fast RGB
IF ErrorLevel = 1 ; IF NOTFound.
{
sleep, 100
}
IF ErrorLevel = 0 ; IF Found.
{
MouseClick, left
sleep, 300
}
} ;-- End of Loop.
return
F8 starts loop and this code checks specific pixel in rectangle and sends left click.
It works with [MouseClick, left, %X%, %Y%].But I want to know how can I use dllcall mouse event to click on specific pixel.
for example
DllCall("mouse_event",uint,1,int,%X%,int,%Y%,uint,0,int,0)
But its not working
I doubt that you actually want to do this via DLL calls. mouse_event doesn't even take coordinates, but values between 0-65535.
If you want to be able to click any pixel on the screen make sure you set it to be relative to the screen: CoordMode, Mouse, Screen
Then use ControlClick/PostMessage/SendMessage if you don't want to affect your mouse pointer by that click. Or use MouseClick/Click. Or MouseMove+Send, {LButton}.

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.

Script to open right-click menu and choose menu item

In a specific program, I want to assign a hotkey to the action of right clicking at the cursor's current position, then moving the cursor to choose an item on that menu, then moving the cursor again to choose an item on the sub-menu. I've gotten as far as the first two commands. When I get to the mousemove, no matter what coordinates I put in, the cursor shoots to the upper left corner of the screen, when what I would like it to do is first move 100 pixels to the right and 60 pixels up, then 100 pixels to the right, zero pixels on the y-axis. Clearly I am misunderstanding something. Please advise.
Thanks,
Ellen
s::
MouseGetPos
Click right
sleep, 100
MouseMove, 60, -60, 5, R
Sleep, 100
MouseMove, 200, 0, 5, R
MouseClick, L
return
Ellen, first of all, if at all possible try if you could use keyboard shortcuts.
Please check: Control Panel\Ease of Access Center\Make the keyboard easier to use\Underline keyboard shortcuts and access keys. This will show the shortcuts that you can use. This way you might even find the keyboard shortcut for the menu, instead of using the mouse location.
^+b:: ; Record the location of the menu at the beginnin with [Shift]+[Ctrl]+b
SoundBeep, 500, 500
ToolTip, Click on the "XYZ" Link
KeyWait, LButton, D
MouseGetPos, xPos, yPos
Send, {Esc}
ToolTip
Return
^b::
MouseClick, Right, xPos, yPos
;Mousemove, 100, 60 R
Send, e : OR WHATEVER Shortcut letter OR.....
Send, {Down 3}{Enter} ; IF you want to use down arrow 3 times to get to the item.
Return
Modified, where YOU have to position the mouse on the always changing menu position.
^b::
MouseClick, Right ; presses where the mouse is located
;Mousemove, 100, 60 R
Send, e : OR WHATEVER Shortcut letter OR.....
Send, {Down 3}{Enter} ; IF you want to use down arrow 3 times to get to the item.
Return
If you can identify the menu ID (with AHK Windows Spy, place the mouse over the menu and look at "under the mouse"), you could use controlsend. This would be location independent since controlsend will use the menu ID to send a signal. If you tell me which application you try to control, I could see if controlSend could be used....
Oh b.t.w. I did not know you used XP, the enable shortcut instructions were for Windows 7.
Shouldn't Mousemove be MouseMove instead? It's like that in the docs.
This AutoHotkey script, including a user-created AutoHotkey function should do what you require.
It automates right-clicking a program, and then selecting 3 items on subsequent menus.
The script has been written to work on Media Player Classic,
but certain lines just need to be edited to make it work for your program, TypeTool 3. You specify a comma-separated list with one or more items, i.e. the name of the item to choose in the first menu, and in the second menu item etc.
The vast majority of programs use standard context menus,
so it should work on your program; this is in contrast
to menu bars and other types of controls/resources that vary more between programs.
-
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...
;the currently assigned hotkey is ctrl+q
;e.g. Media Player Classic, open right-click menu, click items
#IfWinActive, ahk_class MediaPlayerClassicW
^q::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass not in MediaPlayerClassicW
Return
CoordMode, Mouse, Screen
MouseGetPos, vPosX2, vPosY2
WinGetPos, vPosX, vPosY, vPosW, vPosH, ahk_id %hWnd%
vPosX := Round(vPosX + vPosW/2)
vPosY := Round(vPosY + vPosH/2)
MouseMove, %vPosX%, %vPosY%
vList = View,On Top,Default
MenuRCSelectItem(vList)
MouseMove, %vPosX2%, %vPosY2%
Return
#IfWinActive
;===============
MenuRCSelectItem(vList, vDelim=",", vPosX="", vPosY="", vDelay=0)
{
DetectHiddenWindows, Off
CoordMode, Mouse, Screen
MouseGetPos, vPosX2, vPosY2
(vPosX = "") ? (vPosX := vPosX2)
(vPosY = "") ? (vPosY := vPosY2)
if !(vPosX = vPosX2) OR !(vPosY = vPosY2)
MouseMove, %vPosX%, %vPosY%
Click right
Loop, Parse, vList, %vDelim%
{
vTemp := A_LoopField
WinGet, hWnd, ID, ahk_class #32768
if !hWnd
{
MsgBox error
Return
}
oAcc := Acc_Get("Object", "1", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (Acc_Role(oAcc, A_Index) = "menu item")
if (oAcc.accName(A_Index) = vTemp)
if (1, oRect := Acc_Location(oAcc, A_Index), vIndex := A_Index)
break
vPosX := Round(oRect.x + oRect.w/2)
vPosY := Round(oRect.y + oRect.h/2)
MouseMove, %vPosX%, %vPosY%
Sleep %vDelay% ;optional delay
oAcc.accDoDefaultAction(vIndex)
WinWaitNotActive, ahk_id %hWnd%, , 6
if ErrorLevel
{
MsgBox error
Return
}
}
MouseMove, %vPosX2%, %vPosY2%
Return
}
;==================================================

Tooltip on control focus ahk

In Autohotkey, is there a way to detect what gui control has focus so that I display a text box with basically a tooltip.
I want to hover my mouse or use the keyboard to navigate and display what would be stored in the tooltip in a multiline textbox.
I dont want to have a tooltip.
OnMessage(0x0200, "WM_MOUSEMOVE") ; WM_MOUSEMOVE 0x0200
Return
WM_MOUSEMOVE(wParam, lParam)
{
global Control_Name
X := lParam & 0xFFFF
Y := lParam >> 16
MouseGetPos, , , , Control_Name
Tooltip, %Control_Name%, (x+150), (y+150)
}
Esc::ExitApp
ControlGetFocus is used to get the name. See sample code below
a::
ControlGetFocus, OutputVar, A
if ErrorLevel
MsgBox, The target window doesn't exist or none of its controls has input focus.
else
MsgBox, Control with focus = %OutputVar%
Got it! ;-)
I watch if the mouse moves, or a control has focus and display in a text box some stored values
#Persistent
SetTimer, WatchCursor, 100
return
WatchCursor:
MouseGetPos, mx, my, id, mouseControl
ControlGetFocus, currentFocus, A
if (SubStr(mouseControl,1,6)= "Button" OR SubStr(currentFocus,1,6)= "Button")
butIDkey := SubStr(currentFocus,7,2)
butIDmouse := SubStr(mouseControl,7,2)
if (SubStr(mouseControl,1,6)= "Button" && lastmx <> mx && lastmy <> my)
butID := butIDmouse
if (butIDkey <> lastControl)
butID := butIDkey
lastControl := butIDkey
lastmx := mx
lastmy := my
GuiControl,TemplateEngine:, MyTooltip, % Value%butID%
}
return