LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

02 May 2020, 16:22

Howdy!

I used to be pretty active on these forums. I wrote some code, answered (and asked) a ton of questions and released some apps written in AHK. Then life happened and I haven't done much with the language in years. Enter a global plague. I now find I have extra time, and a need for things to do to fill that time. I have a folder, or three, filled with old unfinished and unpolished scripts. I think I shall try to finish some. One in particular was a text replacement/macros app that hit several road blocks. First I needed a way to cleanly cancel the Input command. Standard AHK did not seem to be able to do that, so I asked on here and the developer of AHK_H told me AHK_H can do that. Great! Then I had to learn basic Object syntax. Great! After a lot of work and tinkering I had the core app working (I thought) perfectly, then I got a new PC, upgrading from XP to Win7. One ability of my script was to use the clipboard to paste content rather than have to Send it. Suddenly the script was incapable of interacting with the clipboard under Win7. I tried various adjustments and fixes but nothing worked. For some reason the AHK of that time just had clipboard issues under Win7. So I gave up and archived the project.

That was 5-7 years ago, and a LOT has changed. I started looking at my old code yesterday, trying to decipher this 500 lines of seeming gibberish. I have a vague notion of at least what the code did, even if the HOW is still murky. I needed to consult the docs, so I went online to look at the newest versions for both standard and _H. WOW have things changed! AHK standard now has a Hotstring() function? I remember asking about changes to hotstrings, a command or function so hotstrings could be set dynamically. I was told it wasn't gonna happen. Oh well. This function can't seem to do what I need anyway, since you can't set end characters for individual hotstrings. And there is now a InputHook() object, which may act as a more flexible Input replacement??? It has a Stop option, which MIGHT let me use AHK standard instead of _H, maybe. Anyway, I will be investigating all of these, and figuring out if I need to start from scratch or if I can polish my existing code. I will use this thread to ask questions, probably over several weeks (I am very slow to accomplish things).

For just this moment, I have 1 question: Can someone kindly link me to the current documentation for AutoHotkey_H v1.1? I found it the other day but now I can't find it anywhere. I downloaded the v1.1 zip but even that doesn't have the docs with it. The AutoHotkey_H.chm file in that zip appears mostly empty. What am I missing?

Thank you for your assistance, and for the considerable patience this will no doubt require. :morebeard:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

02 May 2020, 16:31

Hey dmg, nice to see you here again.
AHK_H v2 docs can be found here: http://hotkeyit.github.io/v2/docs/AutoHotkey.htm
Most of the stuff apply to v1.1 as well, let me know if you have any questions.
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

02 May 2020, 16:40

Hi, HotKeyIt! Long time no see. :D

Yes, I found the docs for v2, but they don't help me. For one thing the Input command is not listed at all. I really did find some docs for _H v1.1 the other day. It mentioned a change in how The Input command worked since I last looked at it. I didn't dream it, I promise. :crazy:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

02 May 2020, 18:26

Since the Input code changed quite a bit internally and Input command does not exist in v2 anymore, I have removed the docs. You can access them on github in history commits, that one should be the latest: Input.
Included v1.1 AutoHotkey.chm has it listed under Other changes.
Multi threaded Input
While Input is running the variable will be updated instantly and will be available to script. Use SetTimer or AutoHotkey.dll to grab Input variable while Input is running.
Additional option
Include A in options to append input to the variable (so variable will not be set empty before input starts)
I have just pushed an update to v1.1 because neither the A option nor accessing the variable was working. In latest version all should work fine again.

So you can either use old style:

Code: Select all

SetTimer, MyInput,100
input:="test "
Input, input,A,{Esc}
MsgBox end
ExitApp
MyInput:
ToolTip % input
Return
Or new InputHook object, beside A option, getting input will work in AHK_L too:

Code: Select all

SetTimer, MyInput,100
ih:=InputHook("A","{Esc}")
ih.Input:="test "
ih.Start()
ih.Wait()
MsgBox end
ExitApp
MyInput:
  ToolTip % ih.Input
Return
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

02 May 2020, 19:14

Thank you for the code examples. I will play with them and see what I can figure out. And thank you for replying in general.

Umm... A couple of questions. The _H v1.1 docs are gone? you deleted them except for the html code in that repository??? Why? If you still have v1.1 for download, why do you not still have the docs, preferably with the exe in the zip? I mean I understand if you stopped updating v1.1 to focus on v2, but why delete the most recent documentation that goes with the final version of v1.1????? I had to copy that html code to a file and open in browser to be able to read it. it's not great but it should work. :crazy:
I have just pushed an update to v1.1 because neither the A option nor accessing the variable was working. In latest version all should work fine again.
OK, so there was an issue, with something, and you fixed it? I don't understand what you are referring to, but Good. I downloaded the zip, extracted and tried the chm file. It does not appear to work. it starts blank, and using the search box shows some options in the left box, but no amount of clicking, double clicking or right clicking does anything from there. What am I missing? (I DID warn in my original post that patience would be required)

From what I can tell from the docs, in order to cancel the Input command in progress you can use InputEnd? back when I started my script it was just Input, with no parameters after. It was changed to InputEnd and this works similarly, yes?

Thank you for your help.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

03 May 2020, 03:17

Umm... A couple of questions. The _H v1.1 docs are gone? you deleted them except for the html code in that repository??? Why? If you still have v1.1 for download, why do you not still have the docs, preferably with the exe in the zip? I mean I understand if you stopped updating v1.1 to focus on v2, but why delete the most recent documentation that goes with the final version of v1.1????? I had to copy that html code to a file and open in browser to be able to read it. it's not great but it should work. :crazy:
No, the v1 docs stayed as they are for many years. Only v2 docs changed.
I have just pushed an update to v1.1 because neither the A option nor accessing the variable was working. In latest version all should work fine again.
OK, so there was an issue, with something, and you fixed it? I don't understand what you are referring to, but Good. I downloaded the zip, extracted and tried the chm file. It does not appear to work. it starts blank, and using the search box shows some options in the left box, but no amount of clicking, double clicking or right clicking does anything from there. What am I missing? (I DID warn in my original post that patience would be required)
Yes, there was an issue and it is fixed. For docs, check right mouse -> properties -> Unblock. See https://community.spiceworks.com/topic/1961503-solved-windows-10-chm-help-files-showing-up-blank
From what I can tell from the docs, in order to cancel the Input command in progress you can use InputEnd? back when I started my script it was just Input, with no parameters after. It was changed to InputEnd and this works similarly, yes?
It is still Input, InputEnd is for v2.:

Code: Select all

SetTimer, CancelInput,3000
Input, var
MsgBox % ErrorLevel "`n" var
ExitApp
CancelInput:
Input
Return
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

03 May 2020, 21:41

I apologize for being dense. I do have an excuse though. I have a severe form of ADHD, and a few other issues, that make understanding instructions very difficult. This is also a primary reason I have never been very good at scripting in general. I am finding the process of re-learning to script VERY frustrating.

OK. I am still confused, so I will ask a few more questions. I started with the assumption that AHK_H v1 would have documentation, in basically the same way AHK standard does:
https://www.autohotkey.com/docs/AutoHotkey.htm

I couldn't find it, so I asked to be linked to it. If there is no such thing, then how do people use AHK_H?

When you said:
Since the Input code changed quite a bit internally and Input command does not exist in v2 anymore, I have removed the docs.
I assumed you meant there used to be docs for _H v1 but since you were focusing on v2 you had deleted them. I found this very confusing. What DID you mean?

You also said:
You can access them on github in history commits, that one should be the latest: Input.
With a link to a github repository of a doc page:
https://github.com/HotKeyIt/AutoHotkey_H-Docs/blob/fe248dff22f559cc83822678bd35ea920485ff15/docs/commands/Input.htm
That page references InputEnd as the way to terminate an Input in progress, but you later said InputEnd was just v2. Does that mean that archived doc page is for v2, not v1?

You said:
No, the v1 docs stayed as they are for many years. Only v2 docs changed.
... I am afraid I have no idea what that means.

Your instruction to be able to use the CHM file worked great! thank you. I vaguely remember having to do that years ago, but had forgotten. ... What IS that CHM file? it's nothing like the AHK standard docs. Is it just comments on changes made from standard to _H?

The zip package has 6 different file sets, plus a compiler folder and a few other things. What is the difference between the 6 versions? 32 vs 64 I understand, but what is a, w, and MT? And why is there not even a txt file included to explain anything? :shock:


I recognize these may seem like dumb questions, but I promise iI would not ask if I could find the answers myself. Thank you for your patience.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

04 May 2020, 02:12

The chm file included in downloads was the only available AHK_H v1.1 documentation, there was never another one: https://github.com/HotKeyIt/ahkdll-v1-release/blob/master/AutoHotkey_H.chm
The other documentation was always for AHK_H v2. However, most of the features implemented in v2 were implemented in v1.1 too, so you can use v2 docs as well, just remember that the syntax is a bit different. In the past v2 was not that much different than v1 but not anymore.
I linked to old v2 docs for Input because this was the latest one where Input was mentioned, later Input command was removed, sorry for confusion.

The different files are:
32-bit ANSI
32-bit Unicode
64-bit Unicode

The ones with _MT don't use microsoft redistributable runtime, so they don't depend on vcruntime140.dll.
The downside is that you can't work properly with memory from another thread (AutoHotkey.dll) since it will create access violation.
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

04 May 2020, 03:18

Thank you! That is much clearer.

Sadly, I will probably have to start back at the basics in a lot of ways, just to be able to read my own code. :shock: I think this is the third time since learning AHK that i've let too much time elapse and have to re learn everything. :wtf:

Thank you very much for your help. I will post back to this thread when I have new questions. (hopefully not often, or soon) :geek:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

19 May 2020, 11:10

(This was previously posted on the wrong thread)

I have mostly deciphered my old code... And found MANY problems with it. :lol:

I can sort most of it out myself eventually, but right now I have questions:

I used the input command to monitor typing for use as a very hotkey-like function. Back when I started this I had trouble with using end keys/triggers for replacements. HotKeyIt gave me the solution in AHK_H, since it doesn't empty the Input's variable between Inputs. My question right now is can I make my code do what it should WITHOUT AHK_H? Is there a way to acomplish the same functionality using AHK standard? Maybe using the 'new' InputHook?

Here is a stripped down version of my script, and instructions to run it:

Code: Select all

#singleinstance, ignore
#installkeybdhook
setbatchlines, -1
setworkingdir, %a_scriptdir%

menu, tray, nostandard
menu, tray, tip, Auctus
menu, tray, add, Strings, manage_strings
menu, tray, add, Settings, settings_gui_show
menu, tray, add, About, about_gui
menu, tray, add
menu, tray, add, Exit, exit
menu, tray, default, strings

global format_time, format_date, cliptemp2, sound, prompt

gosub, get_strings
gosub, get_settings
gosub, strings_gui_create
gosub, settings_gui_create

loop
 {
   input, string, aiv, {space}{tab}{enter}{left}{up}{right}{down}, %match%

   key := substr(errorlevel, 8)
   e := instr(options["" . string], "e")
   s := instr(options["" . string], "s")
   t := instr(options["" . string], "t")
   x := instr(options["" . string], "x")

   if (strings["" . string])
    {
      if (options["" . string] = "")
       {
         gosub, set_settings

         send, % "{bs " . (strlen(string)) . "}" . _insert(_replace(strings["" . string], 1), 1)

         string := ""
       }
      else if (e && key = "enter") or (s && key = "space") or (t && key = "tab")
       {
         gosub, set_settings

         send, % "{bs " . (strlen(string)) + 1 . "}" . _insert(_replace(strings["" . string], 1), 1) . "{" . (x ? "" : key) . "}"
       }
    }

   if (key)
    {
      string := ""
    }
 }

~rbutton::
~lbutton::
 {
   input
 }
return

get_strings:
 {
   fileread, text, strings.txt
   options := {}, strings := {}, match := ""
   
   loop, parse, text, `n, `r
    {
      if (a_loopfield != "")
       {
         pos1 := instr(a_loopfield, "|", 0, 1, 1)
         pos2 := instr(a_loopfield, "|", 0, 1, 2)
         match .= substr(a_loopfield, 1, pos1 - 1) . ","
         options.insert("" . substr(a_loopfield, 1, pos1 - 1), substr(a_loopfield, pos1 + 1, pos2 - pos1 - 1))
         strings.insert("" . substr(a_loopfield, 1, pos1 - 1), substr(a_loopfield, pos2 + 1))
       }
    }
   match := rtrim(match, ",")
 }
return

strings_gui_create:
 {
   gui, 1:font, s8
   gui, 1:+delimiter`,
   gui, 1:add, listbox, sort x10 y10 w100 h230 vstrings_list gselected_string
   gui, 1:add, edit, x120 y10 w330 h160 vsel_insert
   gui, 1:add, edit, x10 y240 w100 h20 vsel_string

   gui, 1:add, groupbox, x120 y180 w155 h50 , Triggers
   gui, 1:add, checkbox, x130 y200 w50 h20 vtrig_e, Enter
   gui, 1:add, checkbox, x180 y200 w50 h20 vtrig_s, Space
   gui, 1:add, checkbox, x230 y200 w40 h20 vtrig_t, Tab

   gui, 1:add, groupbox, x285 y180 w165 h50 , Options
   gui, 1:add, checkbox, x295 y200 w60 h20 vopt_c, Use Clip
   gui, 1:add, checkbox, x355 y200 w86 h20 vopt_x, Exclude trigger

   gui, 1:add, button, x120 y240 w60 h20 gstrings_clear, Clear
   gui, 1:add, button, x270 y240 w60 h20 , Delete
   gui, 1:add, button, x330 y240 w60 h20 gstrings_save, Save
   gui, 1:add, button, x390 y240 w60 h20 gstrings_done, Done
 }
return

manage_strings:
 {
   guicontrol, 1:, strings_list, ,%match%
   gui, 1:show, w460 h270, Manage strings
 }
return

selected_string:
 {
   gui, 1:submit, nohide
   sel_insert := strings["" . strings_list]

   e := instr(options["" . strings_list], "e")
   s := instr(options["" . strings_list], "s")
   t := instr(options["" . strings_list], "t")
   c := instr(options["" . strings_list], "c")
   x := instr(options["" . strings_list], "x")

   guicontrol, 1:, trig_e, % e ? 1 : 0
   guicontrol, 1:, trig_s, % s ? 1 : 0
   guicontrol, 1:, trig_t, % t ? 1 : 0
   guicontrol, 1:, opt_c, % c ? 1 : 0
   guicontrol, 1:, opt_x, % x ? 1 : 0
   guicontrol, 1:, sel_insert, %sel_insert%
   guicontrol, 1:, sel_string, %strings_list%
 }
return

strings_clear:
 {
   guicontrol, 1:, strings_list, ,%match%
   guicontrol, 1:, trig_e, 0
   guicontrol, 1:, trig_s, 0
   guicontrol, 1:, trig_t, 0
   guicontrol, 1:, opt_c, 0
   guicontrol, 1:, opt_x, 0
   guicontrol, 1:, sel_insert
   guicontrol, 1:, sel_string
 }
return

guiclose:
strings_done:
 {
   gui, 1:cancel
   gosub, strings_clear
 }
return

strings_save:
 {
   gui, 1:submit
   
   e := trig_e ? "e" : ""
   s := trig_s ? "s" : ""
   t := trig_t ? "t" : ""
   c := opt_c ? "c" : ""
   x := opt_x ? "x" : ""
   
   new_string := sel_string . "|" . e s t c x . "|" . sel_insert
   ;msgbox, % new_string
   fileappend, %new_string%, strings.txt
   
 }
return

settings_gui_create:
 {
   gui, 2:font, s8
   gui, 2:add, groupbox, x10 y10 w70 h85, Method
   gui, 2:add, radio, x20 y30 w40 h20 vmethod1, Input
   gui, 2:add, radio, x20 y50 w50 h20 vmethod2, Event
   gui, 2:add, radio, x20 y70 w40 h20 vmethod3, Play

   gui, 2:add, checkbox, x20 y100 w50 h20 vsound, Sound

   gui, 2:add, groupbox, x90 y10 w210 h50, Press
   gui, 2:add, text, x100 y30 w40 h20 , Delay:
   gui, 2:add, edit, x140 y30 w45 h20 vdelay
   gui, 2:add, text, x195 y30 w50 h20 , Duration:
   gui, 2:add, edit, x245 y30 w45 h20 vduration

   gui, 2:add, groupbox, x90 y70 w210 h50, Formats
   gui, 2:add, text, x100 y90 w30 h20 , Date:
   gui, 2:add, edit, x130 y90 w60 h20 vformat_date
   gui, 2:add, text, x200 y90 w30 h20 , Time:
   gui, 2:add, edit, x230 y90 w60 h20 vformat_time

   gui, 2:add, button, x10 y130 w50 h20 gsettings_default, Default

   gui, 2:add, button, x200 y130 w50 h20 gcancel_settings, Cancel
   gui, 2:add, button, default x250 y130 w50 h20 gsave_settings, Save
 }
return

settings_gui_show:
 {
   guicontrol, 2:, format_date, %format_date%
   guicontrol, 2:, format_time, %format_time%
   guicontrol, 2:, sound, %sound%
   guicontrol, 2:, method%method%, 1
   guicontrol, 2:, delay, %delay%
   guicontrol, 2:, duration, %duration%
   gui, 2:show, w310 h160, Settings
 }
return

get_settings:
 {
   iniread, format_date, settings.ini, settings, date, dd-MM-yy
   iniread, format_time, settings.ini, settings, time, h:mmtt
   iniread, sound, settings.ini, settings, sound, 1
   iniread, method, settings.ini, settings, method, 1
   iniread, delay, settings.ini, settings, delay, -1
   iniread, duration, settings.ini, settings, duration, -1
   format_time := format_time = "" ? "h:mmtt" : format_time
   format_date := format_date = "" ? "dd-MM-yy" : format_date
   sound := sound = "" ? 1 : sound
   method := method = "" ? 1 : method > 3 ? 1 : method
   delay := delay = "" ? -1 : delay
   duration := duration = "" ? -1 : duration
   gosub, set_settings
 }
return

set_settings:
 {
   if (method = 1)
    {
      sendmode, input
    }
   else if (method = 2)
    {
      sendmode, event
    }
   else if (method = 3)
    {
      sendmode, play
    }

   if (method = 2)
    {
      setkeydelay, %delay%, %duration%
    }
   else if (method = 3)
    {
      setkeydelay, %delay%, %duration%, play
    }
 }
return

save_settings:
 {
   gui, 2:submit
   iniwrite, %format_date%, settings.ini, settings, date
   iniwrite, %format_time%, settings.ini, settings, time
   iniwrite, %sound%, settings.ini, settings, sound
   method := method1 ? 1 : method2 ? 2 : method3 ? 3 : ""
   iniwrite, %method%, settings.ini, settings, method
   iniwrite, %delay%, settings.ini, settings, delay
   iniwrite, %duration%, settings.ini, settings, duration
   gosub, set_settings
 }
return

settings_default:
 {
   guicontrol, 2:, format_date, dd-MM-yy
   guicontrol, 2:, format_time, h:mmtt
   guicontrol, 2:, sound, 1
   guicontrol, 2:, method1, 1
   guicontrol, 2:, delay, -1
   guicontrol, 2:, duration, -1
 }
return

2guiclose:
cancel_settings:
 {
   gui, 2:cancel
 }
return

about_gui:
 {
   if (about_gui != 1)
    {
      gosub, get_about
      gui, 3:font, s8
      gui, 3:add, button, x340 y275 w60 h20 ghome_site, Home
      gui, 3:add, button, default x400 y275 w60 h20 g3guiclose, OK
      gui, 3:add, edit, +readonly vscroll x10 y10 w450 h260, %about%
      gui, 3:show, center w470 h300, About Auctus
      about_gui := 1
    }
   else
    {
      gui, 3:destroy
      about_gui := 0
    }
 }
return

get_about:
 {
   about := 
(
""
)
 }
return

home_site:
 {
   msgbox, Home page not yet created...
   ;run, http://crzyinc.weebly.com/Auctus.html
 }
return

3guiclose:
 {
   gui, 3:destroy
   about_gui := 0
 }
return

_replace(text, flag)
 {
   if (flag)
    {
      stringreplace, text, text, ``n, `n, 1
      stringreplace, text, text, #, {#}, 1
      stringreplace, text, text, !, {!}, 1
      stringreplace, text, text, ^, {^}, 1
      stringreplace, text, text, +, {+}, 1
    }
   else
    {
      stringreplace, text, text, ``n, `r`n, 1
    }
   return text
 }

_insert(text, flag)
 {
   stringreplace, na, text, {prompt}, , useerrorlevel
   total := errorlevel
   loop, % total
    {
      prompt := ""
      gui, 4:font, s8
      gui, 4:add, edit, x10 y10 w270 h120 vprompt
      gui, 4:add, button, x180 y140 w50 h20 gprompt_skip, Skip
      gui, 4:add, button, default x230 y140 w50 h20 gprompt_go, Go
      gui, 4:show, w290 h170, Input %a_index% of %total%
      winwaitclose, Input %a_index% of %total%
    }
   
   formattime, time, , %format_time%
   formattime, date, , %format_date%
   stringreplace, text, text, {clip}, %cliptemp2%, 1
   if (flag)
    {
      stringreplace, text, text, `r`n, `n, 1
    }
   stringreplace, text, text, {time}, %time%, 1
   stringreplace, text, text, {date}, %date%, 1
   if (sound)
    {
      soundplay, sound.wav 
    }
   return text
   
   4guiclose:
   prompt_skip:
    {
      gui, 4:destroy
      stringreplace, text, text, {prompt}, %prompt%, 0
    }
   return
   
   prompt_go:
    {
      gui, 4:submit
      gui, 4:destroy
      stringreplace, text, text, {prompt}, %prompt%, 0
    }
   return
 }


exit:
exitapp
Here is the content of the strings.txt file that needs to be in the script folder:

Code: Select all

test|estx|{time} | {date} | {prompt} | {prompt} | {prompt}

~date||Today's date is {date}

~time||The current time is {time}

imho||In my humble opinion

btw|s|By the way,

~sig||Best regards-`nJohn M. Smith
Here is the content of the settings.ini file that needs to be in the script folder:

Code: Select all

[settings]
date=dd-MM-yy
time=h:mmtt
sound=1
method=1
delay=-1
duration=-1
This code has many issues and large chunks that are broken, particularly the GUIs. My question is about the core insert/replace functionality.

Once you have the script, strings and settings files in a folder, run the script in AHK_H, open a notepad window and type "~date", then type "imho", then type "test" with Space, Enter or Tab as end key. In AHK_H endkeys work because the Input variable remembers content between Inputs. When this code is run in AHK standard strings with no endkey still work, but ones using an endkey are broken. Can this be made to work under standard???

I probably explained this badly, so please ask any and all questions. Thank you!
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

19 May 2020, 15:59

cant go through the whole code but to persist the input between calls u store it somewhere(static, global, bound obj, etc)

Code: Select all

ih := InputHook("IV", "{Esc}{Space}{Enter}", "typing,any,of,these,terminates,the,hook")
ih.OnEnd := Func("onEnd")
ih.Start()

onEnd(thisHook) {
	static collectedInput := ""

	collectedInput .= thisHook.Input

	switch thisHook.EndReason
	{
	case "Match":
		MsgBox % "you wrote: '" collectedInput "'`n`nbye"
		collectedInput := ""
		ExitApp
	default: 
		thisHook.Start()
	}
}
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

19 May 2020, 18:20

Hi swagfag. Thanks for replying.

I assume you mean copy the input to a middle-man variable so it's not lost when the Input blanks its variable. That is the only thing that came to mind for me to, only it's more complicated than that. I remember when I first wrote this, something like 7 years ago, that I tried that method in every way I could think of at the time and couldn't get it to work. The problem is that my code has multiple elements that interact with each other in kinda complicated ways, and using a middle-man variable just doesn't take into account all those interactions. Not to say that method CAN'T do the job, I just haven't figured out how yet.

About the code you posted... What is it SUPPOSED to do? I looked at it, ran it several times... I am confused about what it's meant to be demonstrating. :think:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

19 May 2020, 18:41

u start to type words.
characters begin collecting in ih.Input.
hitting any of the EndKeys appends whatever is in the ih.Input's buffer to the intermediary collectedInput and restarts the hook.
typing any of the MatchList words(which, note, is only possible if ih.Input contains the exact word and only it, ie no spilledover garbage characters - or enable FindAnywhere/* option) display a msgbox, resets the collectedInput var and kills the script(or in ur case, presumably, moves onto doing more... productive things)
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

19 May 2020, 19:05

Hmmm, OK. See, the last time I really worked with AHK InputHook() and Switch didn't exist, at all. So your code is about 95% gibberish to me. :crazy:

I will tinker with it and see if I can learn from it and if it can be applied to my problem. Thanks!
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

20 May 2020, 01:22

switch should be closer to 0% gibberish but here it is again without it in case not:

Code: Select all

onEnd(thisHook) {
	static collectedInput := ""

	collectedInput .= thisHook.Input

	if (thisHook.EndReason = "Match")
	{
		MsgBox % "you wrote: '" collectedInput "'`n`nbye"
		collectedInput := ""
		ExitApp
	}
	
	thisHook.Start()
}
and InputHook, well... ure just gonna have to read the docs otherwise its guaranteed 100% gibberish
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

20 May 2020, 08:06

Thanks for the altered code. It is indeed easier to understand. When I said your code looked like gibberish to me I was only explaining why I was having trouble with it, not that I wanted more of an explanation. But thank you. :D
switch should be closer to 0% gibberish
Why would you think that? I had never seen it before, so why "should" I understand it?
and InputHook, well... ure just gonna have to read the docs otherwise its guaranteed 100% gibberish
Oh I HAVE been looking at the docs for InputHook, for over a week. That doesn't mean I can understand it when I see it used in someone else's code. Please don't make the error of assuming my lack of understanding is due to a lack of time or effort on my part. I have never been 'good' at scripting. It takes me longer and more effort than some to learn or write anything, and I try not to post questions often or lightly. :eh:

Thank you again for the help.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

24 May 2020, 09:39

I have been trying to fix this for a few days, and I have realized embarrassingly late that what I am trying to do is not possible. My code relies heavily on the built in monitoring and reactions of the Input command (EndKey and MatchList). So no matter what I do with the content of variables AFTER the Input finishes, the Input itself CANNOT react to that content! I spent days of frustration on this! :problem:

It MIGHT be possible to rewrite it to not rely on Input for anything other than collecting characters, but even if it could be done I do not feel up to figuring it out. And I can't see anything about the InputHook that would make it a viable alternative.

So, it looks like I will not be able to migrate my app to AHK standard after all. Why on earth the very useful A option isn't part of the AHK main branch, I can't comprehend (sigh). :headwall:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

24 May 2020, 10:58

if u explain what im supposed to see(precisely!!) when carrying out these actions
open a notepad window and type "~date", then type "imho", then type "test" with Space, Enter or Tab as end key
and the general purpose of the script, i might be able to come up with something
@HotKeyIt can u explain how the A option is supposed to work with Input(not hook) in ahk_h v1 1.1.32?
when running this code nothing gets appended, only overwritten(which is what it usually does by default anyway)

Code: Select all

; signature: Input OutputVar, Options, EndKeys, MatchList

; type 'asdf', then hit Space
Input collectedInput, AV, {Space}, matchit
MsgBox % collectedInput "`t" ErrorLevel ; asdf	EndKey:Space


; dismiss the msgbox with the mouse, then type 'matchit'
Input collectedInput, AV, {Space}, matchit
MsgBox % collectedInput "`t" ErrorLevel ; matchit	Match

; ??? where is the appended input stored - 'asdfmatchit'

ExitApp
Esc::ExitApp
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

24 May 2020, 17:13

Looks like yours is not the latest version, download current release and try again.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: LONG STORY. Input/InputHook(), Hotstring(), AHK_H, ETC

24 May 2020, 17:26

yeah it works now, it was from april

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder and 363 guests