One part of my script can't send "F6"-key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

One part of my script can't send "F6"-key

11 Sep 2017, 04:06

Hello!

I have a hotkey that should do some stuff, and one of those things is send "F6" to get to the URL-bar. See below:

Code: Select all

!l::

; Write to the array:
ArrayCountNY = 0
Loop, Read, D:\censored   ; This loop retrieves each line from the file, one at a time.
{
    ArrayCountNY += 1  ; Keep track of how many items are in the array.
    ArrayNY%ArrayCountNY% := A_LoopReadLine ; Store this line in the next array element.
}

MsgBox, 4,, censored
IfMsgBox Yes 
{
    mastercountNY = 0
    Loop %ArrayCountNY%
	{
		;Åpne sider
		Sleep, 50
		Send {F6}
		Pause
		Sleep, 50
		Clipboard = % ArrayNY%A_Index%
		Sleep, 50
		Send ^v
		Sleep, 50
		Send {enter}
		Sleep, 1500

		
		Send ^a
		Sleep 50
		Clipboard := ""
		Send, ^c
		ClipWait, 2
		page := clipboard
		Sleep 50
		Loop , parse , page , `n
			{
				lineNY := A_LoopField 
				outputdebug %lineNY%
				if lineNY contains Summering
				{
					StringSplit, value_arrayNY, lineNY, %A_Space%%A_Tab%
				}
			}
		
		
		mastercountNY += 1
		masterarrayNY%mastercountNY% = %value_arrayNY4%
		
	}

	MsgBox, 4,, censored
	IfMsgBox Yes 
	{
		Loop %mastercountNY%
			{
				Send % masterarrayNY%A_Index%
				Sleep, 150
				Send {down}{sleep 10}{down}{sleep 50}{down}
			}
			
	}

	else ifMsgBox No
	{
		Return
	}
}

else ifMsgBox No
{
	Return
}

Return
I added a pause after Send {F6} because it does not work. I have literally copied that entire section from another part of my script where it still works, so I have no idea why it would not work. If I do this:

Code: Select all

!y::
		;Åpne sider
		Sleep, 50
		Send {F6}
Return
It works perfectly. So I don't understand. What happens when I get to that part of the script is that one of the folders on my row of bookmarks get selected. Pressing F6 manually takes me to the URL bar. Pressing F+6, F, 6, alt+f etc. does not take me to selecting that folder. I really, really don't understand anything.

Thanks!
User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: One part of my script can't send "F6"-key

11 Sep 2017, 06:13

It may be that your window doesn't have time to become active after you dismiss the MsgBox. You can try adding a WinWaitActive and a Sleep before the Send.
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: One part of my script can't send "F6"-key

11 Sep 2017, 06:20

You seem to be correct, but is this a bug? Why is the window not active, I wonder? Because if I add a 2500 ms delay I get the same problem, but if I click the window before the delay is over, the F6 keysend works.

What can I do to make the window active? Why is it not active in this spesific hotkey, but the two others work perfectly fine in the same window even without a long sleep?

Thanks again!
User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: One part of my script can't send "F6"-key

11 Sep 2017, 06:35

Was the window active before you hit the alt-L key? You can try WinActivate to ensure it is active.

It's also possible that a certain pane in the window gets focus when you click on it while just letting the window become active does not.

It's not a bug. It's just a matter of making sure the window is active and possibly also that the part of the window that receives the F6 key has focus.
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: One part of my script can't send "F6"-key

11 Sep 2017, 06:50

Hello again!

I think there is a bug somewhere, but not in AHK. If I use WinActivate I get the same problem. But if I use WinActivate on another Chrome window it actually works. And the exact same message box with the same code works on another hotkey in the same window that this one does not work. That is what's bugging me. But I think I can get past this by making the script open a new tab before pressing F6 :)

Thanks for the input!
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: One part of my script can't send "F6"-key

11 Sep 2017, 06:56

Ah, no I can't, because it's in a loop. I just can't seem to figure this out. WinActivate just works sometimes, does not matter how long delay I have. But what I see is that pressing F6 manually twice in a row brings me from the URL-bar to the bookmark that the key seems stuck on. But I only have the script press it once. Setting a slower key delay did not work either.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, mmflume, OrangeCat, ShatterCoder and 81 guests