I am brand new to auto hot key and have been trying to troubleshoot an auto hot key script that turns a strobe light off and on in a radio studio. We have an existing hot key script that's been in use for a few years, but I don't know if the script was recently corrupted, since I didn't create it and the person who did has since left my workplace. I'm interested in just starting over with a new script, and don't know how to get started. The script needs to watch AP news wire stories and turn on the strobe light whenever an urgent news alert comes in.
Thanks,
elizabeth
Turn strobe light off and on
-
- Posts: 3
- Joined: 29 Jun 2022, 14:47
Re: Turn strobe light off and on
Hi Elizabeth(d), welcome to the AHK Forum.
The most common, and the practical way would be to show/share that script so your supporters can sort out its details and trigger/improve/fix it.
So...
The most common, and the practical way would be to show/share that script so your supporters can sort out its details and trigger/improve/fix it.
So...
-
- Posts: 3
- Joined: 29 Jun 2022, 14:47
Re: Turn strobe light off and on
Code: Select all
; AutoHotkey Version: 1.0.40.11
; Language: English
; Platform: WinXP
; Author: halweg
; Send keysequences to dialog boxes
;**************************************************************************************
;******************************* Initialization ***************************************
;**************************************************************************************
;!!! Change the next two lines as required !!!
inifile = C:\Users\jduchesn\Documents\AutoHotkey112400_ansi\closewindow.ini
title_of_a_new_notepad_window = Untitled - Notepad
COORDMODE, TOOLTIP, SCREEN
SETTITLEMATCHMODE, 1
DETECTHIDDENTEXT, ON
DETECTHIDDENWINDOWS, ON
;*** Read saved keysequences
number_of_dialogs := my_iniread("Dialoge", "Number_of_dialogs")
LOOP, %number_of_dialogs%
{
wtitle%A_INDEX% := my_iniread("Dialoge", "Title" . A_INDEX)
wtext%A_INDEX% := my_iniread("Dialoge", "Text" . A_INDEX)
wkeys%A_INDEX% := my_iniread("Dialoge", "Keys" . A_INDEX)
}
;*** Start the dialog-watching
last_id = leer
SETTIMER, handle_dialog_boxes, 2000
RETURN
;**************************************************************************************
;*************************** Timed dialogbox handler **********************************
;**************************************************************************************
handle_dialog_boxes:
;*** It's time so look for new active windows
new_id := WINEXIST("A")
IF new_id <> %last_id%
IFWINEXIST, Priority Alert
{
;*** run putty session to talk to relay
Run C:\Program Files (x86)\PUTTY.exe -load "NBRelay"
Sleep, 500
IFWINEXIST, 129.93.104.28-PuTTY
{ WinActivate, 129.93.104.28-PuTTY
Sleep, 500
Send {Enter}
Sleep, 1000
Send setstate,1:1,1 {Enter}
Sleep, 500
Send getstate,1:1 {Enter}
Sleep, 500
Send setstate,1:1,0 {Enter}
Sleep, 500
WinClose, 129.93.104.28-PuTTY
Sleep, 1000
Send {Enter}
}
Sleep, 4000
WinClose, Priority Alert
}
{
last_id =%new_id%
;*** A new window was found - Now: Compare the active window's title with all saved titles one by one
LOOP, %number_of_dialogs%
IFWINEXIST, Priority Alert
{
;*** run putty session to talk to relay
Run C:\Program Files (x86)\PUTTY.exe -load "NBRelay"
Sleep, 500
IFWINEXIST, 129.93.104.28-PuTTY
{ WinActivate, 129.93.104.28-PuTTY
Sleep, 500
Send {Enter}
Sleep, 1000
Send setstate,1:1,1 {Enter}
Sleep, 500
Send getstate,1:1 {Enter}
Sleep, 500
Send setstate,1:1,0 {Enter}
Sleep, 500
WinClose, 129.93.104.28-PuTTY
Sleep, 1000
Send {Enter}
}
Sleep, 4000
WinClose, Priority Alert
}
keys_to_send := wkeys%A_INDEX%
title_to_watch := wtitle%A_INDEX%
text_to_watch := wtext%A_INDEX%
;*** Window title found - Now: Does it contain the right text?
WINGETTEXT, act_wintext, A
IFINSTRING, act_wintext, %text_to_watch%
{
;*** The text is ok - Now: Do we need a SLEEP?
IFINSTRING, keys_to_send, SLEEP
{
STRINGLEFT, sleeptime, keys_to_send, 4
STRINGTRIMLEFT, keys_to_send, keys_to_send, 9
SLEEP, %sleeptime%
}
;*** SLEEP was done - Now: Send the keys
my_beeps(2, 70)
timed_tooltip("Sending """ . keys_to_send . """", 2000)
SEND, %keys_to_send%
;*** Keys was sent - Now: Watch the dialogbox disappears
WINWAITCLOSE, %title_to_watch%, %text_to_watch%, 2
IF ERRORLEVEL = 1
MSGBOX, No success!`nThe actual Window couldn't be handled by ""%keys_to_send%""
}
}
}
}
RETURN
;**************************************************************************************
;************************* Registration of a new dialog-handling keysequence **********
;**************************************************************************************
SCROLLLOCK::
my_beeps(1, 70)
;*** 1. Analyse the current active window (dialogbox to be registered)
WINGETTITLE, new_title, A
WINGETTEXT, all_window_text, A
;*** 2. User should select a significant piece of text from the dialogbox window by notepad
CLIPBOARD =
RUN notepad.exe
WINWAITACTIVE, %title_of_a_new_notepad_window%
SETKEYDELAY, -1
SEND, %all_window_text%
SETKEYDELAY, 10
MSGBOX, Plese select (by mouse) a significant piece (maximum one line) of text to identify the dialogbox in future`nThen press OK
SEND, ^c
new_text = %CLIPBOARD%
;*** Close notepad without changes
SEND, !{BS}!{F4}
;*** 3. User should input the keysequence for future handling of the dialogbox
INPUTBOX, new_keys, Dialog-Box Handler for %new_title%,
(
Please enter a keyssequence that should handle this dialogbox in future. Use AHK - codes.
If the dialogbox needs a delay, include a SLEEP time in ms.
EXAMPLES:
my_name{TAB}my_password{ENTER}
2500SLEEP{TAB}1234{ENTER}
)
IF ERRORLEVEL = 0
{
IF new_keys =
MSGBOX, Please Enter at least one key!
ELSE
{
;*** 4. Test the new keysequence, ask if the dialogbox was handled successful
WINACTIVATE, %new_title%
keys_to_send = %new_keys%
IFINSTRING, new_keys, SLEEP
{
STRINGLEFT, sleeptime, new_keys, 4
STRINGTRIMLEFT, keys_to_send, new_keys, 9
SLEEP, %sleeptime%
}
my_beeps(2, 70)
timed_tooltip("Sende" . keys_to_send, 5000)
SEND, %keys_to_send%
MSGBOX, 36, Successful dialogbox handling?, Save new Keysequence?
IFMSGBOX, Yes
{
;*** 5. Save dialogbox data
new_number_of_dialogs := number_of_dialogs + 1
INIWRITE, %new_number_of_dialogs%, %inifile%, Dialoge, Number_of_dialogs
INIWRITE, %new_title%, %inifile%, Dialoge, Title%new_number_of_dialogs%
INIWRITE, %new_text%, %inifile%, Dialoge, Text%new_number_of_dialogs%
INIWRITE, %new_keys%, %inifile%, Dialoge, Keys%new_number_of_dialogs%
;*** 6. Enable the handling of the new dialogbox in the current script
wtitle%new_number_of_dialogs% := new_title
wtext%new_number_of_dialogs% := new_text
wkeys%new_number_of_dialogs% := new_keys
number_of_dialogs := new_number_of_dialogs ;*** Enable the Dialogwatching of the new registred dialogbox
timed_tooltip("The Window """ new_title """`nText """ new_text """`nin future will be handled by """ new_keys """",5000)
my_beeps(1, 500)
}
}
}
RETURN
;**************************************************************************************
;********************************** Functions ****************************************
;**************************************************************************************
;*** This function makes a number of beeps
my_beeps(number, duration)
{
LOOP, %number%
{
SOUNDBEEP, 650, %duration%
SLEEP, 50
}
}
;*** This function shows a tooltip and will close it later
timed_tooltip(text, milliseconds=2000)
{
TOOLTIP, %text%, 0, 0
SETTIMER, close_tooltip, %milliseconds%
}
close_tooltip: ;*** Closes the standard tooltip
SETTIMER, close_tooltip, Off
TOOLTIP
RETURN
;*** This function reads a value from the inifile and will finish the script if ERROR value detected
my_iniread(m_section, m_key)
{
global inifile
INIREAD, m_value, %inifile%, %m_section%, %m_key%
IF m_value = ERROR
{
MSGBOX, An Error was encountered while reading inifile`nKey: %m_key%
,`nsection:%m_section%
,`nfile:%inifile%
EXITAPP
}
ELSE
RETURN %m_value%
}
Last edited by BoBo on 01 Jul 2022, 15:15, edited 1 time in total.
Reason: Added [code][/code]-tags.
Reason: Added [code][/code]-tags.
Re: Turn strobe light off and on
Obviously, you're acting in a "Germanized" environment (womit es von Vorteil sein könnte, im Deutschen AHK Unterforum anzufragen!)?
AFAICS, the AHK-Forum member @halweg (the developer of this script) has been registered as "active" only a few days ago
So, if there's nothing fundamentally against it, he might be your first choice to sort this out?!
a) I'd recommend starting with AHK v.2 if you're in touch with AHK for the first time. That way you're up to date in the long run (converting that script following that syntax)
b) try to get "local admin rights" if possible. That will provide you with more options by default (even if not used ATM, and not necessary for this particular case/script).
c) if you're forced to work with an older AHK release prior to AHK v.2 go for the latest possible one (well, no prob if you re-create that script from scratch).
d) just in case you're providing code, especially used within a working environment, check for embedded login- or other sensitive data and use dummy data instead.
e) good luck & viel Spaß mit AutoHotkey
PS: not sure if this is in any kind related to what you're intended to do (or have to change!): https://www.ap.org/discover/Media-API JFTR
AFAICS, the AHK-Forum member @halweg (the developer of this script) has been registered as "active" only a few days ago
So, if there's nothing fundamentally against it, he might be your first choice to sort this out?!
a) I'd recommend starting with AHK v.2 if you're in touch with AHK for the first time. That way you're up to date in the long run (converting that script following that syntax)
b) try to get "local admin rights" if possible. That will provide you with more options by default (even if not used ATM, and not necessary for this particular case/script).
c) if you're forced to work with an older AHK release prior to AHK v.2 go for the latest possible one (well, no prob if you re-create that script from scratch).
d) just in case you're providing code, especially used within a working environment, check for embedded login- or other sensitive data and use dummy data instead.
e) good luck & viel Spaß mit AutoHotkey
PS: not sure if this is in any kind related to what you're intended to do (or have to change!): https://www.ap.org/discover/Media-API JFTR
Re: Turn strobe light off and on
It's interesting an over 10 years old version of this script is still alive.
Of course there are newer versions, new features and functions. But also a more complex library structure, the code increases 20 times.
Unfortunately I've no time for support. The only thing I sometimes distribute is the compiled version...
Of course there are newer versions, new features and functions. But also a more complex library structure, the code increases 20 times.
Unfortunately I've no time for support. The only thing I sometimes distribute is the compiled version...
Re: Turn strobe light off and on
@elizabethd
Assuming that b) the puTTY-connection is still your interface of choice, is anything wrong with doing it via puTTY's command line (if possible)?
So a) how do you get that AP News? What's its source format? A stream, capture from a webpage, document ie JSON/XML via its API, ...?The script needs to watch AP news wire stories and turn on the strobe light whenever an urgent news alert comes in.
Assuming that b) the puTTY-connection is still your interface of choice, is anything wrong with doing it via puTTY's command line (if possible)?
-
- Posts: 3
- Joined: 29 Jun 2022, 14:47
Re: Turn strobe light off and on
I'm not sure exactly how autohotkey reads data from AP Wires. I was told that autohotkey will quickly open and close a telnet session with putty Plink, but I don't know how that was configured either. I'm open to trying other interfaces.
Thanks.
Thanks.
Re: Turn strobe light off and on
Well, that's the very first thing you've to find out, and based on its outcome you can start automating things.I'm not sure exactly how autohotkey reads data from AP Wires.
As your current script is really outdated (taking halweg's statement from above into account) you should check out if AP News provides an API that is built to do data harvesting on-the-fly.
Who is online
Users browsing this forum: Google [Bot] and 161 guests