SendInput is sluggish, stops

Get help with using AutoHotkey and its commands and hotkeys
kunkel321
Posts: 176
Joined: 30 Nov 2015, 21:19
Facebook: https://www.facebook.com/kunkel321
Google: kunkel321

SendInput is sluggish, stops

30 Jan 2019, 17:30

Hi Folks,

This script works well for the most part, but often it is sluggish and slow entering text, and sometimes the part where it enters text will just stop.
Firstly, let me point out that this was written several years ago with MUCH help from people on the forum here -- Thank you all!
The script, briefly,
1 - Reads from a couple of text files (that are formatted as INI files).
2 - Launches a GUI using parameters from the text file, and prompts for input.
3 - Based on that input, it reads some of the text from the text file.
4 - StringReplaces several text strings, then
5 - Types the modified, chosen boilerplate text into a webform for me, tabbing between fields.

The SendInput command is on line 94, about 80% of the way to the bottom.

Code: Select all

#NoEnv ; For security
#SingleInstance force
#Persistent
SetWorkingDir %A_ScriptDir% 
;################################

;Menu, Tray, Icon, C:\Users\SWKunkel\AutoHotkey\AutoCorrect\Icons\IconPencilThick.ico Commented out for forum.
Gui, t2:Destroy
	Gui, t2:-MinimizeBox +alwaysOnTop
Gui, t2:Font, s12
Gui, t2:Add, Edit, x21 y16 w200 h25 vStudentName, Name  ;Box to type in name.
Gui, t2:Font, s10
Gui, t2:Add, Radio, x11 y42 w50 h20 vGender checked, &Male ;Radio group for gender.
Gui, t2:Add, Radio, x80 y42 w70 h20 , &Female 
Gui, t2:Add, Radio, x160 y42 w80 h20 , &Neutral
Gui, t2:Font, s7
gui, t2:add, Text, x160 y1, Version 1-15-2019 ; This separates the radio groups.
Gui, t2:Font, s10
IniRead, AllSchools, SchoolList.txt ;Gets `n-delimited list from ini file.
Loop, Parse, AllSchools, `n,`r  ; Parses list.
 Gui, t2:Add, Radio, x12 gMySchChoice, %A_LoopField% ;Dynamically make one radio button per item.
MySchChoice:  ;Activates when someone chooses a school (?)
MySchChoice := A_GuiControl
IniRead, AllNotices, NoticeDefinitions.txt ;Gets `n-delimited list from ini file.
Loop, Parse, AllNotices, `n,`r  ;Parses list.
 Gui, t2:Add, Button, gMyChoice, %A_LoopField% ;Dynamically make one cmd button per item.
Gui, t2:Font, s8
Gui, t2:Add, Button, t2x x12 section w45 h30 , About ;Auto-positioned button on the bottom.
Gui, t2:Add, Button, ys x61 section w45 h30 , Edit`nSchools 
Gui, t2:Add, Button, ys x110 section w45 h30 , Edit`nNotices
Gui, t2:Add, Button, ys x159 section w45 h30 , Close
Gui, t2:Show, ,NOA Tool (Alt+Shift+W)

if (AllSchools = ERROR) || (AllNotices = ERROR)  ; Will catch if either INI is missing.
{
    MsgBox, 262192, Error Reading File, There was a problem reading from the "SchoolList.txt" file or from the "NoticeDefinitions.txt" file.`n`nPlease exit, then ensure that they are in the same folder as the NOAtool.ahk and the NOAtool.exe files.  The two text (.txt) files should be formatted as Windows .ini files. 
   return
}
; Menu, Tray, Icon, C:\Users\SWKunkel\AutoHotkey\AutoCorrect\Icons\IconPencilThick.ico commented out for forum post.
return

MyChoice: ; Goes here when a button (notice type) is clicked.
IniRead, MyNoticeChoice, NoticeDefinitions.txt, %A_GuiControl%  ; From notice type, goes back to INI, gets notice content.
gui submit 
IfEqual, StudentName, Name ;Catches if student name hasn't been changed from default.
{
   MsgBox Student name?
   gui, t2:show
   return
}
if (MySchChoice = ERROR)   ;If no school has been selected, assigns first one in INI.
{
      StringSplit, FirstSch, AllSchools, `n,`r
      ;MsgBox First school is %FirstSch1%
      MySchChoice = %FirstSch1%
}

IfEqual, Gender, 1 ;Checks the results of the gender radio buttons group and assigns variables.
{
   varHeShe = he
   varHimHer = him
   varHisHer = his
}
IfEqual, Gender, 2
{
   varHeShe = she
   varHimHer = her
   varHisHer = her
}
IfEqual, Gender, 3
{
   varHeShe = they
   varHimHer = them
   varHisHer = their
}

IniRead, MyContactInfo, SchoolList.txt, %MySchChoice%, Contact-info ; From school choice, gets contact info.
IniRead, MySchPhone, SchoolList.txt, %MySchChoice%, Sch-Phone

StringReplace MyNoticeChoice, MyNoticeChoice, [n], %StudentName%, All ; Makes the replacements.
StringReplace MyNoticeChoice, MyNoticeChoice, [e], %varHeShe%, All
StringReplace MyNoticeChoice, MyNoticeChoice, [m], %varHimHer%, All
StringReplace MyNoticeChoice, MyNoticeChoice, [s], %varHisHer%, All
StringReplace MyNoticeChoice, MyNoticeChoice, [c], %MyContactInfo%, All
StringReplace MyNoticeChoice, MyNoticeChoice, [p], %MySchPhone%, All
StringReplace MyNoticeChoice, MyNoticeChoice, !, ., All  ; Because ! and # are special keys.
StringReplace MyNoticeChoice, MyNoticeChoice, #, No., All

MyNoticeChoice =`n%MyNoticeChoice% ; Adds an new-line at beginning so regex will work.
;CulledNotice := RegExReplace(MyNoticeChoice,"(\n)+[ a-zA-Z0-9]+=")  ; Removes all Key names.
CulledNotice := RegExReplace(MyNoticeChoice,"(\n)+[ a-zA-Z0-9,/&+.\-#]+=")  ; Removes all Key names. Added special chars 9-2-18.
;MsgBox %StudentName%'s school is %MySchChoice%, Gender is %varHeShe%/%varHimHer%/%varHisHer%, `n`nNotice:`n%CulledNotice%`n`n%MyContactInfo%
StringReplace, CulledNotice, CulledNotice,`n, , All ; Gets rid of any leftover <Enter>s.
SendInput, %CulledNotice%  ; Types notice into text field(s) 
ExitApp ; replaced Return with Exitapp on 1-24-2019 and got rid of the extra Gue, t2:Destroy.

AboutHandler:
t2ButtonAbout:  ; The 4 buttons at bottom of form go to these.
;Run, AboutGVTool2.docx
MsgBox, 262192, , 'Last update was 1-15-2019.'
return

SchoolListHandler:
t2ButtonEditSchools:

Run, C:\Program Files\Just Great Software\EditPad Pro 7\EditPadPro7.exe "C:\Users\swkunkel\AutoHotkey\AutoCorrect\NOAtool\SchoolList.txt"
;run, SchoolList.txt
Gui, t2:Show
return

NoticeDefHandler:
t2ButtonEditNotices:
Run, C:\Program Files\Just Great Software\EditPad Pro 7\EditPadPro7.exe "C:\Users\swkunkel\AutoHotkey\AutoCorrect\NOAtool\NoticeDefinitions.txt"
gui, t2:show
return

t2ButtonClose:
t2GuiClose: ; Red button in corner of form.
Gui, t2:Destroy ; Destroy and start at top to forget the variables.
ExitApp
I can't perfectly recreate the "sluggishness effect." Sometimes it types out normally, sometimes not. Several times I've tried launching it in a text editor, and I've never had a problem when doing so. This tells me that it might have to do with the web browser, Internet Explorer, or the webform or website. Oddly, the times that the SendInput completely stops, it ALWAYS types out exactly one word of my boilerplate text, then stops. It has never typed two words, or a half-a-word, then quit. Honestly, I can live with the sluggishness/slow typing, but the stopping effect messes up my groove.

I doubt if anyone will be able to recreate this effect, but if anyone wants to try... The following text files must be in the same folder as the .AHK file.

this one must be named NoticeDefinitions.txt

Code: Select all

;==================================================================
;===	THIS FILE MUST BE IN SAME FOLDER AS TOOL EXE File.	===
;===	THIS FILE MUST BE FORMATTED AS A WINDOWS INI FILE.	===
;==================================================================
; Replacement keys to use below:
; [n] is changed to: student name as entered in the popup form
; [e] is changed to: he/she/they as chosen on the form
; [m] is changed to: him/her/them
; [s] is changed to: his/her/their (note singular/plural grammar) 
; [c] is changed to: Contact-info (see SchoolList.txt) 
; [p] is changed to: School-phone (see SchoolList.txt) 
;####################################################################

[Referral for TESTING]
Educational Concerns=^{a}{Delete}This notice documents that [n] has been identified as a candidate for an evaluation of eligibility for special education services.
Jump={Tab}
Summary of Existing=^{a}{Delete}Information in [n]'s file, as well as input from [s] teachers and guardians indicates a history of interventions that have not successfully remediated [s] educational needs. 
Jump={Tab}
Previous Ed Interventions=^{a}{Delete}Previous interventions was included such things as small group instruction and one-on-one help
;Review school interventions and put above.
Jump={Tab}{Tab}
Enrollment in Other Progs=^{a}{Delete}Other progs here.  Also my contact info: [c].  And just my phone number is [p].
Jump={Tab}{Tab}
Health Screening=^{a}{Delete}[n]'s most resent vision and hearing screenings indicates functioning that is within normal limits. 

;======================================================================
[Referral Notice when Candidate]
Any other factors=^{a}{Delete}Please find the attached consent-for-evaluation form. Upon receipt of [n]'s consent-for-eval form we will begin the evalation process. Remember that this consent form is only for the evaluation.  If [n] does qualify for an Individualized Education Program (IEP), then you'll need to sign an additional permission form for us to start [s] services.  Please call if you have any questions. [c]
Jump={Tab}{Tab}

Other options rejected=^{a}{Delete}No other options were really applicable.  A file reivew and input from parents and staff suggest that an evaluation is appropriate at this time.
Jump={Tab}{Tab}

Reason rejected=^{a}{Delete}N.A.
Jump={Tab}{Tab}

Based on these procedures=^{a}{Delete}This is based on the recent referral for special education testing.
Jump={Tab}

;======================================================================
[Referral Notice when NOT A Candidate]
Any other factors=^{a}{Delete}Other factors...
Jump={Tab}{Tab}

Other options rejected=^{a}{Delete}Opt rejected..
Jump={Tab}{Tab}

Reason rejected=^{a}{Delete}WWHy?
Jump={Tab}{Tab}

Based on these procedures=^{a}{Delete}Based on this...
Jump={Tab}



;======================================================================
[PWN--Transfer ACCEPT]
Description of Action=^{a}{Delete}This notice communicates to you that we have confirmed [n]'s eligibility for IEP supports and we will begin providing those services.
Jump={Tab}{Tab}

Reason for Action=^{a}{Delete}This is based on information from [s] previous distrcit, which indicates [e] has an IEP.
Jump={Tab}{Tab}

Other Factors=^{a}{Delete}Please call if you have any questions: [c]
Jump={Tab}{Tab}

Options Rejected=^{a}{Delete}Redoing the eligibility evaluation and the IEP.
Jump={Tab}{Tab}

Reasons Rejected=^{a}{Delete}The paperwork from the previous distriction seems appropriate, so it doesn't need to be redone.
Jump={Tab}{Tab}

Based on or Proposed procudures=^{a}{Delete}This is based on [n]'s transfer paperwork.  

;======================================================================
[PWN--Transfer NOT ACCEPT]
Description of Action=^{a}{Delete}This notice communicates to you that we have reviewed [n]'s IEP documents from [s] previous district.  They will need to be updated.  We will initiate a reevaluation.
Jump={Tab}{Tab}

Reason for Action=^{a}{Delete}This is based on information from [s] previous distrcit, which indicates [e] has an IEP.
Jump={Tab}{Tab}

Other Factors=^{a}{Delete}Please call if you have any questions: [c]
Jump={Tab}{Tab}

Options Rejected=^{a}{Delete}Not applicable.  We will have to redo the eligibility evaluation to conform to Wa State regulations.
Jump={Tab}{Tab}

Reasons Rejected=^{a}{Delete}N/A
Jump={Tab}{Tab}

Based on or Proposed procudures=^{a}{Delete}This is based on [n]'s transfer paperwork.  

;======================================================================

[PWN Need to do TRIennial REEVAL]
Description of Action=^{a}{Delete}This form notifies you that we need to do [n]'s three-year reevaluation for [s] IEP services. 
Jump={Tab}{Tab}

Reason for Action=^{a}{Delete}The reevaluation allows us to see what progress [e] has made and document that [e] does (or does not) still require IEP services.
Jump={Tab}{Tab}

Other Factors=^{a}{Delete}(1)Please note that we are required to do the reevaluation, even if you don't return the attached permission form. (2)If you have any questions or information for the reeval, please contact me: [c]
Jump={Tab}{Tab}

Options Rejected=^{a}{Delete}None applicable.  Reevaluations are required by law.  
Jump={Tab}{Tab}

Reasons Rejected=^{a}{Delete}None applicable/Noting rejected. 
Jump={Tab}{Tab}

Based on or Proposed procudures=^{a}{Delete}Reevaluations are usually based on a file review, observations, input from teachers and parents, and testing.  See also attached permission form. 

;======================================================================

[Reeval Caveat Statement]
Tests=^{a}{Delete}This will likely involve updated reading, writing, and math testing with the Woodcock-Johnson Test of Achievement-4th (WJ-IV).  [n]'s social/emotional/behavioral levels will likely be assessed with the Behavior Assessment System for Children-Third Ed. (BASC-3) rating scales. This includes questionnaires for teachers and parents and has an optional student self-rating component.{Enter}
NOTE: The form says below that we cannot proceed with [n]'s evaluation unless you sign and return this form.  For RE-evaluations, such as this one, we are actually required to do the reevaluation (unless a waiver has been signed) even if this form is never returned.  Also, with initial evaluations, there is a strict 35-school-day @@@@@

[PWN Consent for Initial EVAL]
Description of Action=^{a}{Delete}This form notifies you that we are seeking consent to do an evaluation-of-eligibility for [n].
Jump={Tab}{Tab}

Reason for Action=^{a}{Delete}An evaluation determines whether [e] qualifies for, and is in need of, an Individualized Education Program (IEP). 
Jump={Tab}{Tab}

Other Factors=^{a}{Delete}(1) Please note that this consent form is only for the evaluation.  If [n] does qualify, you'll need to sign an additional consent form before [e] can start IEP services. (2) If you have any questions or information for the eval, please contact me: [c]
Jump={Tab}{Tab}

Options Rejected=^{a}{Delete}Not doing the evaluation.
Jump={Tab}{Tab}

Reasons Rejected=^{a}{Delete}An evaluation does seem to be appropriate at this time. 
Jump={Tab}{Tab}

Based on or Proposed procudures=^{a}{Delete}This is based on referral conserns as well as information from parents and a file-review.  

;======================================================================
and this one must be named SchoolList.txt

Code: Select all

;==================================================================
;===	THIS FILE MUST BE IN SAME FOLDER AS TOOL. 		===
;===	THIS FILE MUST BE FORMATTED AS A WINDOWS INI FILE.	===
;===	[Section] Names get used in the Form's Radio  Buttons.	===
;===	Key Names should be "Contact-info" or "Sch-Phone".	===
;==================================================================

[&KMS]
Contact-info=Stephen Kunkel, xxxxxxxxxxxxxxxxxxxxxxx
Sch-Phone=12345

[&NKHS]
Contact-info=Stephen Kunkel,xxxxxxxxxxxxxxxxxxxxxxx
Sch-Phone=12345667

[Wolfle]
Contact-info=Stephen Kunkel, xxxxxxxxxxxxxxxxx
I re-read this page
https://autohotkey.com/docs/commands/Send.htm
Looking for things to try, to remedy this, but didn't see anything useful.... What would you guys try?
safetycar
Posts: 125
Joined: 12 Aug 2017, 04:27

Re: SendInput is sluggish, stops

31 Jan 2019, 16:44

I have not tried it, but I see the ExitApp right after that. I'd try to give it Sleep, 10000 or so if the text is quite big. Maybe that helps?
kunkel321
Posts: 176
Joined: 30 Nov 2015, 21:19
Facebook: https://www.facebook.com/kunkel321
Google: kunkel321

Re: SendInput is sluggish, stops

19 Feb 2019, 14:37

Hi Safetycar,
I just wanted to pop in and say thanks. I'm currently trying this. At first it wasn't working, but I just noticed that I didn't have the comma in it. Am going to try again.
swagfag
Posts: 2754
Joined: 11 Jan 2017, 17:59

Re: SendInput is sluggish, stops

19 Feb 2019, 15:33

do u have other keyboardhooked scripts running in parallel? look at SendInput's caveats: https://www.autohotkey.com/docs/commands/Send.htm#SendInputDetail
also SendInput can only send 5k chanrs max, the rest gets chopped off
also dont use Send for typing long strings, rather paste from the clipboard
kunkel321
Posts: 176
Joined: 30 Nov 2015, 21:19
Facebook: https://www.facebook.com/kunkel321
Google: kunkel321

Re: SendInput is sluggish, stops

20 Feb 2019, 18:02

A good thought swagfag. I actually do have a much-altered version of the most excellent autocorrect script that runs constantly in the background. So even though that script is not getting activated during the use of my above script, I suppose that it is "hooking" the keyboard ?? I'm not sure.

Anyway, I tried exiting the autocorrect script, and the above script still had problems. Lately it seems to be getting worse. It runs slower and completely stops more often. As mentioned in the top post, the problem never occurs if I run the tool in a text editor or in Word. So it probably has do do with Internet Explorer, or the website I'm typing into.

As you've suggested, I probably will try just pasting the text in. This will be a pain though. Each webform that I have to deal with has multiple fields. So the text from SendInput is like "Stuff for first field{Tab}Stuff for second{Tab}et cetra." Now I guess I'll have to parse up the text and move though the webform, pasting the different parts.

Re Safetycar's recommendation of using Delay: This was also a good thought, but didn't work. I also tried putting

Code: Select all

Critical
before and after SendInput. That also did not help.
======

An interesting off-topic side note: When trying the Delay command, I monitored the Win Task Manager (had it open and off to the side) so I could see the actual Autohotkey.exe process and when it terminated. With my original script, the process would terminate immediately after the GUI disappeared, and the text would type out afterward. This was not a surprise, because I figured that the text just gets buffered by the computer. What DID surprise me, is that the Delay command didn't stop this. I then made a simple test script--as follows:

Code: Select all

#NoEnv ; For security
#SingleInstance force
#Persistent

!^+d::
MsgBox "Hello world."

Sleep, 20000
MsgBox "Awake now!"

ExitApp
Interestingly, the process in taskmanager stays open as long as "Hello world" is open, but as soon as you click OK, the process stops. Then, 20 seconds later, "Awake now!" appears, even though the process has long since disappeared from taskman. Seems odd to me. But I dunno. Shouldn't the process stay until the script ends? And that shouldn't happen until ExitApp, which can't run until after the second MsgBox--correct?
User avatar
jeeswg
Posts: 6547
Joined: 19 Dec 2016, 01:58
Location: UK

Re: SendInput is sluggish, stops

20 Feb 2019, 20:04

You could try this:

Code: Select all

SendInput, {Text}hello ;requires AHK v1.1.27+
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
safetycar
Posts: 125
Joined: 12 Aug 2017, 04:27

Re: SendInput is sluggish, stops

21 Feb 2019, 09:48

Don't worry too much about ExitApp, it doesn't seem to be the problem.

The thing about task manager is because it lists program differently if they have a window than if it not. But a process can be running without windows. Also one process can have several windows. It's normal.

Try to follow what jeeswg is saying.
kunkel321
Posts: 176
Joined: 30 Nov 2015, 21:19
Facebook: https://www.facebook.com/kunkel321
Google: kunkel321

Re: SendInput is sluggish, stops

21 Feb 2019, 12:34

Thanks for the additional feedback. The {Text} text mode thing resulted in it typing a caret. "^" I do indeed have 1.1.28.0

As it turns out, I may have fixed the problem by dumping Internet Explorer. In retrospect, this is probably the first thing I should have tried... The only reason that I even use it is because it honors the Windows default printer. Chrome just prints to wherever it was last used. I work at different locations each day so that causes problems.

When I couldn't get AutoHotKey to cooperate, my backup plan was to use MacroExpressPro. Well MEpro doesn't even work AT ALL in the webform when using IE. I tried the same form, but accessed it with Chrome. In Chrome, both MEpro and AHK both seem to work. Strangely they don't seem to work at first. Nothing appears for 2 or 3 seconds, then all of the text suddenly appears at once, as though all of the different text fields got pasted into at once. We'll see if it continues to work.

Anyway, thanks again!

Return to “Ask For Help”

Who is online

Users browsing this forum: begenner at Ahk, Bing [Bot], contabaiswa, Google [Bot], ianjf, teadrinker and 196 guests