How to generate a keypress automatically?

Started by Thom Blair III, August 19, 2018, 10:06:38 PM

Previous topic - Next topic

Thom Blair III

I'm new here and starting to learn the basics of modding. I am wondering how to generate a keypress event. How can I do this? (I don't know how to use Harmony yet if that's the answer.)

When I asked this question on Stack Overflow, they wanted to know "what I was trying to generate  a keypress into" and I didn't know the answer. What programming language do mods use in XML files? (I'm only learning how to edit them right now, not DLLs)
I was surprised to read about Angkor Thom in Cambodia. I looked up what "Thom" means and it's "big" or "great", so my avatar icon is ធំ which is "Thom" in Khmer.

Jaxxa

1. When do you want this to happen?
2. What do you want to happen?

Most likely it will be easier to call some piece of code directly instead of trying to add a key event.

QuoteWhat programming language do mods use in XML files?
Extensible Markup Language
https://en.wikipedia.org/wiki/XML

XML is its own Language that is used for Data Storage.


FueledByOCHD

While I am new as well to modding. But without knowledge of c# you will not be able to generate a key press event, If I am wrong please feel free to let me know. but from what I understand of modding RimWorld is the Def's are meant mainly for data that is meant to be use in game.

Thom Blair III

#3
Quote from: Jaxxa on August 19, 2018, 10:23:02 PM
1. When do you want this to happen?
2. What do you want to happen?
I have a mod (Allow Tool) that will unforbid everything on the map if you press the Home key. So, I was thinking about having the mod generate a Home keypress every Rimworld hour or so. It's an easy way to collect freshly killed animals for free meals and also keep rotting animals from accumulating.

Quote
Extensible Markup Language
XML is its own Language that is used for Data Storage.
Thank you! People on Stack Overflow yelled at me and said XML is not a language, it's a file format.
I was surprised to read about Angkor Thom in Cambodia. I looked up what "Thom" means and it's "big" or "great", so my avatar icon is ធំ which is "Thom" in Khmer.

Jaxxa

Quote from: FueledByOCHD on August 19, 2018, 10:23:35 PM
While I am new as well to modding. But without knowledge of c# you will not be able to generate a key press event, If I am wrong please feel free to let me know. but from what I understand of modding RimWorld is the Def's are meant mainly for data that is meant to be use in game.

I agree, this sounds like something that will need C#.

Quote from: Thom Blair III on August 19, 2018, 10:35:17 PM
I have a mod (Allow Tool) that will unforbid everything on the map if you press the Home key. So, I was thinking about having the mod generate a Home keypress every Rimworld hour or so. It's an easy way to collect freshly killed animals for free meals and also keep rotting animals from accumulating.

As far as I know you will need to use C# .dll files todo this in Rimworld. Also it is most likely better to make a mod that calls the "unforbid everything on the map" code directly instead of simulating a keypres.

Quote from: Thom Blair III on August 19, 2018, 10:35:17 PM
Thank you! People on Stack Overflow yelled at me and said XML is not a language, it's a file format.

Its not a programming language, it is a Markup language. A file format is not too bad a way of thinking of it. But I don't think it will be much use for this mod.


You could also look at non mod solutions, such as a program like AutoHotKey.

Thom Blair III

Quoteit is most likely better to make a mod that calls the "unforbid everything on the map" code directly instead of simulating a keypres.
Ah! Awesome idea, I didn't think of that! That should be much easier.

QuoteYou could also look at non mod solutions, such as a program like AutoHotKey.
Yes, I was thinking about this, but modding (when I can do it) is as much fun as the game itself!  :D  It feels like I get to participate in the game with the pawns, doing research, constructing necessary things, helping out the colony! Like meta-gaming. :)

Thanks for all the input!
I was surprised to read about Angkor Thom in Cambodia. I looked up what "Thom" means and it's "big" or "great", so my avatar icon is ធំ which is "Thom" in Khmer.

Thom Blair III

So, I found the section of Allow Tool mod responsible for unforbidding all things:
<AllowTool.ThingDesignatorDef>
        <defName>AllowAllDesignator</defName>
<designatorClass>AllowTool.Designator_AllowAll</designatorClass>
<category>Orders</category>
<insertAfter>AllowTool.Designator_Forbid</insertAfter>
        <label>Unforbid everything</label>
<description>Unforbids all forbidden items on the map.
Click to activate.</description>
<iconTex>allowAll</iconTex>
<dragHighlightTex>allowHighlight</dragHighlightTex>
<soundSucceeded>TickHigh</soundSucceeded>
<hotkeyDef>DesignatorAllowAll</hotkeyDef>
<messageSuccess>Allow_all_success</messageSuccess>
<messageFailure>Allow_all_failure</messageFailure>
</AllowTool.ThingDesignatorDef>


So, judging by this, I would need a routine that calls/executes/runs (I'm not sure what the term is) DesignatorAllowAll every X ticks then starts the tick counter again. Does this seem like something that can be done in XML? If not, I am familiar enough with programming languages that I think I might be able to cobble together a C+ routine that does this, unless referencing/calling DesignatorAllowAll in the code is somehow complex. What do you think?
I was surprised to read about Angkor Thom in Cambodia. I looked up what "Thom" means and it's "big" or "great", so my avatar icon is ធំ which is "Thom" in Khmer.

FueledByOCHD

Why would you need to make a c+ routine? you could do same thing probably easier in c#, unless that is what you meant

Thom Blair III

Whoops! Thank you, I actually didn't catch that C# is a language now. I've been out of the programming loop for so long the last one I worked with was C++. I'll check out C# and see what it's like. Thanks!
I was surprised to read about Angkor Thom in Cambodia. I looked up what "Thom" means and it's "big" or "great", so my avatar icon is ធំ which is "Thom" in Khmer.

Canute

Or in this case, you use a script program like AutoIt, and this script simulate a keypress each hour.
You can use the record/capute thing, and just edit the resulting script about the delay/timer.
But ofcouse you can learn c# for further use of your modding career ! :-)

FueledByOCHD

If you use HugsLib then you can easily use the features of that by attaching to the Tick Method

RawCode

who need to generate "key A pressed" when you can directly execute action, that will happen when player pressed said key?

also unity do not have such volatile and hard to manage events, instead you can check what keys pressed now in safe and non blocking manner, you can read about how to implement keys properly in unity manual.

if you want keys and events anyway, read about interrupts and threading, and probably you selected wrong game to mod, you really don't need c++ low level stuff for unity game, code injection is only exception.

Thom Blair III

Thanks! I'll check out HugsLib when I get a chance. Until then, I'm just using a little AppleScript that just presses Home every 143 seconds/3 Rimworld hours. It works perfectly so far, but I'd like to get more into modding, so thanks for all the input!
I was surprised to read about Angkor Thom in Cambodia. I looked up what "Thom" means and it's "big" or "great", so my avatar icon is ធំ which is "Thom" in Khmer.

FueledByOCHD

Your welcome and hope you enjoy the modding :)