Hotkey in Excel stops before finishing

Get help with using AutoHotkey and its commands and hotkeys
AbooMatta
Posts: 2
Joined: 03 Dec 2019, 18:40

Hotkey in Excel stops before finishing

03 Dec 2019, 18:53

I have a script that draws a design in Excel by filling cells with a color. It will only run 5 or 6 of the lines before it stops. If I run the script 4 lines at a time, it executes them all correctly. The script is like the following, but it is 300 lines in total. Each line is identical, except for the number of times i press the arrow key.

Here is a sample with eleven of the lines:

Code: Select all

^1::
sendinput, {shift down}{right 1006}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{right 1006}
sendinput, {shift down}{down 541}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{down 541}
sendinput, {shift down}{right 261}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{right 261}
sendinput, {shift down}{up 378}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{up 378}
sendinput, {shift down}{left 530}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{left 530}
sendinput, {shift down}{up 165}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{up 165}
sendinput, {shift down}{left 175}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{left 175}
sendinput, {shift down}{up 143}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{up 143}
sendinput, {shift down}{right 162}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{right 162}
sendinput, {shift down}{down 504}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{down 504}
sendinput, {shift down}{right 985}{shift up}{alt down}{h 2}{alt up}{down 4}{right 6}{enter}{right 985}
send, {f5}azz10000{enter}
return
I wonder if it is a limitation of Excel or if AutoHotKey has an issue with a very long script.
Thanks
User avatar
Datapoint
Posts: 76
Joined: 18 Mar 2018, 17:06

Re: Hotkey in Excel stops before finishing

03 Dec 2019, 22:33

Hi AbooMatta,

Your script is probably sending keystrokes faster than Excel can handle. If one step takes Excel a bit more time to do but your script keeps sending stuff in the meantime then the script will get out of sync with Excel.

Maybe try adding Sleeps between some actions to try to improve the reliability.

Or you could do it with COM instead of Send. Check out the Basic Ahk_L COM Tutorial for Excel for starters.

For example, with Excel running

Code: Select all

; https://docs.microsoft.com/en-us/office/vba/api/excel.application(object)
Excel := ComObjActive("Excel.Application")

; https://docs.microsoft.com/en-us/office/vba/api/excel.application.range
; https://docs.microsoft.com/en-us/office/vba/api/excel.interior.color
Excel.Range("A1:A100").Interior.Color := 0x0055FF ; 0xBBGGRR (BRG = blue green red, 00-FF)
AbooMatta
Posts: 2
Joined: 03 Dec 2019, 18:40

Re: Hotkey in Excel stops before finishing

05 Dec 2019, 11:56

Thank you very much Datapoint. You hit the nail on the head with your suggestion to use Sleep. The AutoHotkey must have been overrunning my buffer. I had to put a Sleep command after every line, especially the long ones, to allow the computer to catch up.

Thanks again,
AbooMatta

Return to “Ask For Help”

Who is online

Users browsing this forum: braunbaer, kunkel321, malamutus, malcev, mikeyww and 49 guests