How to update AutoHotkey GUI Text control? - user-interface

I am trying to display and update a gui element (text string). Can someone tell me what I am doing wrong here? The initial text is never replaced by the updating text in the loop.
kills=0
#n::
Gui,Add,Text,vStatus, starting the killing
Gui,Show,w250 h375
Loop
{
GuiControl,,vStatus, killed %kills% Glorks!
kills+=1
Sleep,3000
}
return

Here is working code:
kills=0
#n::
Gui,Add,Text,vStatus, starting the killing
Gui,Show,w250 h375, Glorks counter
Loop
{
IfWinNotExist, Glorks counter
{
Gui, Destroy
return
}
GuiControl,,Status, killed %kills% Glorks!
kills+=1
Sleep,3000
}
return
Your mistakes:
You should use Status instead of vStatus in GuiControl command.
When you close GUI, you are not stopping loop, so IfWinNotExist detect if window exists and if not exists it will destroy all gui variables and exit from loop. So you can again press Win+n and start gui again.
Note:
If you want to start count kills every time from 0 when gui is started then move kills=0 to right after #n::

Related

AutoHotKey If Key pressed while win11 TaskView is open syntax

I've recently been using Gnome 41.5 and fell in love with the way the Activities menu works
So I am trying to use AHK to create a script that when I press the windows key it opens Task View - then if Task View is open and I start to type, (to search for an application) I want AHK to open the start menu so that I can utilize its search function
My rough outline for how I imagine it would work below - I've been trying to learn but got stuck here
Lwin::
Send, #{Tab}
if (""taskview is open"" + ""any char pressed"") {
Send, Rctrl + Esc
}
In the future I'd love to have the start button just appear on the Task View screen so that it's almost just like Gnome
i wanted to do the same thing and got this so far, i like how this works tbh, but you might wanna add RWin as well (i don't have it, so i didn't)
before task view appears the start menu flashes shortly, but the activation timing keeps shortcuts working without opening task view, so it's a good tradeoff imo.
;couldn't check these names bc the names are different based on system language
;double click on the script in the task tray and hit CTRL+K to figure out the correct name
taskView := "Task View" ;these 2 names are guesses
search := "Search"
;----------------------------------------------------------------------
;Hotkey function hotkeys have to be created first
Hotkey, ~*LButton, mousedown, off
Hotkey, ~*RButton, mousedown, off
Hotkey, ~*MButton, mousedown, off
Hotkey, ~LWin, showTask
;checks every half second if you're in task view to activate the key logging
SetTimer, taskInput, 500
return
showTask:
;prevent repeats
keywait, LWin
;cancel if a different key got pressed while win was held down
if (A_PriorKey != "LWin") {
return
}
if WinActive(taskView){
sleep 1
send {Esc}
return
}
else send #{tab}
taskInput:
if (!WinActive(taskView)){
return
}
Mouse_Flag = 0
Hotkey, ~*LButton, on
Hotkey, ~*RButton, on
Hotkey, ~*MButton, on
;wait for any key
Input, key, L1 V, {VK0E}{LWin}{RWin}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Pause} ;excluded: {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{CapsLock}{NumLock}{PrintScreen}{Left}{Right}{Up}{Down}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}
if WinActive(taskView){
if (key = LWin) {
keywait, LWin
sleep 1
send {Esc}
}
else if (Mouse_Flag || key = Chr(27)) { ;chr 27 = blank space character, matches some characters specified in the any key input check, notably Esc
;nothing/return
}
else {
;open search
send #s
WinWaitActive %search%
if("LWin" != A_PriorKey && key != A_PriorKey){ ;slight fix if you type very fast and the letters get jumbled bc winwaitactive takes too long
send {BS}
send {%key%}
send {%A_PriorKey%}
}
else send {%key%}
}
}
Hotkey, ~*LButton, off
Hotkey, ~*RButton, off
Hotkey, ~*MButton, off
Return
mousedown:
Mouse_Flag = 1
sendevent, {Blind}{VK0E} ;unused virtual key
return

open luakit windows of specific size from shell script

can anybody help me achieving this with luakit?
I'm running raspbian on rpi3 and for my application I need one luakit window constantly running in full screen mode and triggered by a bash script, I want another browser window open from time to time in a certain size e.g. 800x600. Would be nice if I could also determine the position of the second window.
I was able to launch luakit in full screen or specific size by overwriting the window function in my rc.lua config. I then launch luakit with either the one or the other rc.lua file (-c parameter) . However if one instance of luakit is already running, the second luakit window uses the config of the first one that is already running.
Can I somehow trigger the window size of a new luakit window from bash script?
Thanks for any help.
I found a solution to my problem: instead of giving the browser instance the window size, I let itself decide whether or not to launch in fullscreen by checking the URL.
in my rc.lua I added require "userconf" and created a file userconf.lua in which I have overwritten the function window.new like so:
function window.new(uris)
local w = window.build()
-- Set window metatable
setmetatable(w, {
__index = function (_, k)
-- Check widget structure first
local v = rawget(w, k)
if v then return v end
-- Call each window index function
for _, index in ipairs(window.indexes) do
v = index(w, k)
if v then return v end
end
end,
})
-- Setup window widget for signals
lousy.signal.setup(w)
-- Call window init functions
for _, func in pairs(window.init_funcs) do
func(w)
end
-- Call window init functions
for _, func in pairs(window.init_funcs) do
func(w)
end
-- Populate notebook with tabs
for _, uri in ipairs(uris or {}) do
w:new_tab(w:search_open(uri), false)
end
-- Make sure something is loaded
if w.tabs:count() == 0 then
w:new_tab(w:search_open(globals.homepage), false)
end
-- Set initial mode
w:set_mode()
-- Show window
w.win:show()
-- we check the url, if it points to the URL i want to see in fullscreen we launch in fullscreen otherwise we leave the default.
-- open myapplication.html in fullscreen, every other window in normal mode
w.win.fullscreen = false
for _, uri in ipairs(uris or {}) do
if string.match(uri, "myapplication.html") then
print "got myapplication.html"
w.win.fullscreen = true
end
end
return w
end
It's probably not a 100% solution, but for me it's ok

Fix multiple middle mouse click

Basically I have an issue where the middle mouse button when clicked does multiple very fast middle mouses. For example, if I open a link in a new tab with middle mouse it will open about 10 of that tab. I have tried all of the conventional methods to fix it, ie. driver fixes etc. What I want to try now is a bit of mouse debouncing with AHK (Auto Hot Key) for windows.
Essentially what I am thinking is to do this:
while (forever)
if( capture the middle mouse)
sleep 500 ms
mouse click
end
end
Can anyone give some advice with this approach?
Alternatively i thought about making a middle mouse hotkey:
$MButton::
Loop
{
sleep 500
if not GetKeyState("MButton", "P")
break ; Break out of the loop.
}
send {MButton}
return
Can anyone see any problems with this?
You can have a much simpler solution without a delay.
This will ignore middle click if the last click was 50 ms ago.
#Persistent
global pressed_g := 0
global delay_g := 50 ; delay in miliseconds, increase this value if your multiple click take longer than delay_g time
return
MButton::
if( pressed_g = 0 )
{
Send, {MButton}
tooltip,sent
pressed_g := 1
}
SetTimer, Countdown , Off
SetTimer, Countdown , -%delay_g%
return
Countdown:
pressed_g := 0
return
Could it be that you are looking for this? You press the MButton and while you keep the MButton pressed, the script will continue to fire MButton.
#Persistent
MButton::
while GetKeyState("MButton", "P") ; While the Middle Mouse button key is being held down
{
Send, {MButton}
}
return

MATLAB exiting loop in function when using GUI

I have a function which runs when a button is clicked and that function will call another function to perform plotting, which is an animation composed by a series of loops. Problem is, after the program is run, it cannot be stopped unless pressing Ctrl+C which then cause the whole .exe to fail and require reopening it.
I want to make a Reset button, so to stop the loop from running, but how to pass a new variable from the interrupt to the existing function which is two level above the stack?
Thank You
edit # 22:13 27/3/2011 (UKT)
a more clearer of what I am trying to do:
function push_calculate_Callback(hObject, eventdata, handles)
(List of parameters read in the GUI)
fmain(list of paramters required to pass to the function, fmain)
that's first part of the code which linked directly to the GUI, the fmain looks like:
function fmain(List of parameters)
(List of calculations...)
fplotting(list of paramters for plotting)
in which the fplotting is where the animation comes out from, inside the fplotting:
function fplotting(list of parameters)
for i = 1:(end)
(do the animation plot)
end
here is the loop where I want to stop when I press the reset button. coz if anyone press Ctrl+C when the animation is undergoing (looping), it will give an error and the exe file will crash and requires reopening it. So what I want it be able to stop it when someone press the reset button.
If I use persistent, the new value, after I press the reset button, it will not pass into the existing loop and break the loop... looks like I am looking for a way to update the parameter after I have change it outside the function
Thanks
Use exit or quit to exit the program
To stop the loop from running, you can use break or return from a function..
Your best bet might be to use a PERSISTENT variable whose state you check at each iteration of the loop in function 2, and whose value you modify in the "reset"-callback.
reset callback
function reset_callback(hObj,eventdata,handles)
%# "activate" persistent variable
persistent breakThis
%# set it to 1
breakThis = true;
function with the loop
function functionWithTheLoop(someInput)
...
%# "activate persistent variable
persistent breakThis
...
%# start loop
for iter = 1:numOfIterations
%# check whether you need to break out of the loop
if breakThis
%# reset the function value
breakThis = false;
break;
end
...
end
You can use application data information, i.e. setappdata and getappdata:
% animation loop function
function loop(hFig)
setappdata(hFig, 'run', true); % here or somewhere else...
while(getappdata(hFig, 'run'))
plot(....);
end
end
% GUI stop-loop btn callback
function stop(hFig)
setappdata(hFig, 'run', false);
end
I guess that would work.

Assign hotkeys to windows (and remember size & location). AHK

I have found the following script for dynamically assigning hotkeys to already open windows:
Code (Expand):
Loop 10
{
i := A_Index - 1
HotKey #^%i%,DynHotkey
HotKey #%i%, DynHotkey
HotKey #!%i%,DynHotkey
}
Exit
DynHotkey:
StringRight i, A_ThisHotKey, 1
StringMid what,A_ThisHotKey, 2, 1
var := var%i%
IfEqual what, ^, WinGet var%i%, ID, A ; Save ID
Else IfEqual what,!, WinMinimizeAll ; MinimizeAll
WinRestore ahk_id %var%
WinActivate ahk_id %var% ; Switch
Return
(the code was copied from this thread http://www.autohotkey.com/forum/topic38773.html&highlight=dynamic+hot+key)
With the above script you can:
Use Win+Ctrl+0..9 to attach hotkey to current active window.
Use Win+0..9 to switch to correspoding window.
However, if I assign a hotkey to a given window (using Win+Ctrl+0..9), and then I want I want to go back to that window (Win+0..9), the window is reset to a new size & location.
Is there way of saving the size & location of the window along with it's ID?
If so, what would the script look like?
I am running the above script on Windows 7 64-bit.
Thanks a lot,
You dont need to complicate the code :)
Quick question: if your window is minimized you dont have any problems right?
The "problem" on the code is the WinRestore.
The thing is that if the window is not minimized and then you do a WinRestore it will change the size and position to the "not maximized" version of it.
WinActivate automatically does a WinRestore only if the window is minimized, so you can safely remove line 16 (the WinRestore one) since WinActivate will do what you need.
--edit--
this is how the code should look:
Loop 10
{
i := A_Index - 1
HotKey #^%i%,DynHotkey
HotKey #%i%, DynHotkey
HotKey #!%i%,DynHotkey
}
Exit
DynHotkey:
StringRight i, A_ThisHotKey, 1
StringMid what,A_ThisHotKey, 2, 1
var := var%i%
IfEqual what, ^, WinGet var%i%, ID, A ; Save ID
Else IfEqual what,!, WinMinimizeAll ; MinimizeAll
WinActivate ahk_id %var% ; Switch
Return
I tested it, it works perfectly.
You can use WinGetPos to read the actual position and save it. Then you can use WinMove to set the position. Here is a function list: http://www.autohotkey.com/docs/commands.htm.

Resources