Sending keypresses to "Factorio" window.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Taurondir
Posts: 3
Joined: 26 Sep 2020, 10:00

Sending keypresses to "Factorio" window.

27 Sep 2020, 09:30

PS: Im trying to do it via GUI buttons (AutoGUI), I dont want to use "HotKeys" on keyboard to do this.

I'm just trying to make an AutoHotKey GUI program that will eventually open the Crafting window and send a string, because I want to make a little GUI with buttons to allow me to find items on the menu faster.
All of that is irrelevant right now, I'm just mentioning it for context.

Because I'm new at this, all I'm trying to do now is send ONE key to Factorio to make it sure it sees it. For example "E" just opens the crafting menu.
I don't know how to send to the correct window atm.

For Notepad, all the examples use "Edit1" to identify a Notepad window, like such for a button:

ButtonNotepad:
xx := "Notepad text"
ControlSend, Edit1,{Text}%xx%, ahk_class Notepad
return

Now THAT WORKS FINE fine, as the open Notepad window will get the text line "Notepad text" appearing into it. But that's because it gets identified via that "Edit1" tag, which is still confusing to me because WinSpy does show a class "Edit" but only when dragging the cursor INTO the text part of the window. Is "Edit1" the "1"st instance? I dont understand that.

Now, for Factorio, WinSpy just shows "Factorio" being a name in the boxes, but doing this:


ButtonFactorio:
xx := "e"
ControlSend, Factorio,{Text}%xx%, Factorio
Return

does not seem to send an "e" to the window. also "ControlSend, Factorio 1.0.0" - because the _window title_ is "Factorio 1.0.0" is not working.


I'm just trying to find how to TARGET the string "send" to the Factorio window, I'm obviously getting the command wrong or the window handle wrong ... ???
All Im trying to do is send ONE keypress (letter) to make something happen.

Anything obvious Im doing horribly wrong? I can send text to Notepad, I just cant target Factorio right now.
User avatar
mikeyww
Posts: 27044
Joined: 09 Sep 2014, 18:38

Re: Sending keypresses to "Factorio" window.

27 Sep 2020, 11:32

You're exactly right. See the documentation for ControlSend. The "Edit1" of Notepad is the control name, not the window class. Window Spy can show you a control name for your target window's control, or you can leave it blank and just retain the comma in the command. The window title can include the first word or few words of the title (for example), an "ahk_exe" designation with the process name, or both (in addition to other possibilities as documented).

Code: Select all

ControlSend,, {Text}%xx%, Factorio
This exact command may not always work. You will have to experiment, see if a control specification is needed, etc. The documentation also describes how you can use the parent window as another option or possibility.
Taurondir
Posts: 3
Joined: 26 Sep 2020, 10:00

Re: Sending keypresses to "Factorio" window.

27 Sep 2020, 11:53

EDIT 2:

ControlSend,,e,Factorio

works like this apparently :/
the extra "{Text}%xx%" I was putting in because I though it was meant to be there from the Notepad examples, but I'll figure it out how to send from a variable on my own.

Thanks for help.

----------------------------------------------------

Based on this image https://imgur.com/aNX85Fl

The line should(?) be just :

ControlSend,Factorio,{Text}%xx%,Factorio
or even
ControlSend,,{Text}%xx%,Factorio

... but its not working atm. I even just opened Factorio's chat window to see because if I was sending was sending "e" to that window it would show there.
I dont know :( but thanks for reply, I'll look around and see if I can find another way to reference the game window other then the ways I tried already.
Last edited by Taurondir on 27 Sep 2020, 12:25, edited 1 time in total.
User avatar
mikeyww
Posts: 27044
Joined: 09 Sep 2014, 18:38

Re: Sending keypresses to "Factorio" window.

27 Sep 2020, 12:23

As I mentioned, if you specify a second parameter, then it has to be a control name, and your Window Spy is not showing one, so specifying "Factorio" as the control name will not work. If you are sending to the active window, then you can just use Send instead of ControlSend without difficulty. For activating traditional menus, WinMenuSelectItem is a good choice, but that probably will not work here. Would try Send because it is likely to get you closer to your goal.
Taurondir
Posts: 3
Joined: 26 Sep 2020, 10:00

Re: Sending keypresses to "Factorio" window.

27 Sep 2020, 12:29

Yep, thanks for help.

{TEXT} mode was the issue. The line works with just that removed.

I have something working now, and targeting the window was the only realistic issue, as now I can just focus on what to send and work on that problem.
User avatar
mikeyww
Posts: 27044
Joined: 09 Sep 2014, 18:38

Re: Sending keypresses to "Factorio" window.

27 Sep 2020, 14:51

I'm not sure why {Text} would hurt if you are sending only text characters, but good if you have it working now.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, serenite and 196 guests