Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DF app controller source code example  (Read 724 times)

Andruin

  • Escaped Lunatic
    • View Profile
DF app controller source code example
« on: April 07, 2008, 08:52:00 am »

I've just uploaded an example of how to control DF from a different application.

It uses the Windows message system to send keypresses from the app to DF.

There is one quirk - I had to add a delay between keypresses to keep from losing them. I didn't lose any when typing into the app and sending those to DF, but saw major losses when reading from a file and then sending that data to DF. The delay amount may need to be adjusted for other computers, but since this is a proof-of-concept I hard-coded a value that worked for me.

Please note that this is source code only. I'm not comfortable uploading executables....

Feel free to do what you want with the source code. Consider this the rescinding of my rights to it.

Here's the link:
http://dffd.wimbli.com/file.php?id=93

And here's the description at that link:
The enclosed source code shows how to control DF from a second application. This example shows two things:
1) It accepts keypresses and forwards them to DF.
2) The "File/Open" menu selection opens and parses a "loadout" file, sending the specified item selections to DF as though you entered them manually.

Notes:
DF needs to be running, though it can be started either before or after this program.
For the "File/Open" (loadout) command, DF needs to be in the item selection screen ("prepare for the journey carefully" then tab to the items screen.) This command will remove the default selections by sending 105 VK_SUBTRACT keypresses (numpad -), then will send the keypresses needed to select the items listed in the loadout file. See loadout.txt for an example.
This only works on Windows.
There is almost no error checking.
This does not directly change DF memory.

Logged
Andruin

Mel_Vixen

  • Bay Watcher
  • Hobby: accidently thread derailment
    • View Profile
Re: DF app controller source code example
« Reply #1 on: April 07, 2008, 10:01:00 am »

Om i think i have maybe found your Bug in the inifile of DF.

quote:

[KEY_HOLD_MS:150]

This controls the number of milliseconds that must pass before input works again after the view recenters on an event in dwarf mode.


A Filereadout could send the "keypressed"-Message much faster then the 150 miliseconds try a timer to create some delay between the Messages.

Logged
[sarcasm] You know what? I love grammar Nazis! They give me that warm and fuzzy feeling. I am so ashamed of my bad english and that my first language is German. [/sarcasm]

Proud to be a Furry.