Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Scripting, SHIFT+ENTER and 40d9  (Read 1501 times)

Sinergistic

  • Bay Watcher
    • View Profile
Scripting, SHIFT+ENTER and 40d9
« on: March 06, 2009, 05:35:53 pm »

Hello!

Has anyone managed to get shift+enter to work in scripts with 40d9? Every time I try and implement a (shiftdown)(enter)(shiftup) behavior in a script, the script runs fine, but DF doesn't seem to accept that it's getting sent a (shiftdown) command, and treats the (enter) as just one press, instead of the (shift+enter) press it really is. This makes building things with scripts really annoying, since I need to have to script press enter once for each construction.

For example, what I have to do to make the script work with DF:
Code: [Select]
Send("{UP 5}{LEFT}{u 2}{ENTER 5}")
Sleep(500)
Send("{UP 2}{LEFT}{u}{ENTER 5}")

And what I WANT to be able to do
Code: [Select]
Send("{UP 5}{LEFT}{u 2}{+ENTER}")
Sleep(500)
Send("{UP 2}{LEFT}{u}{+ENTER}")
{+ENTER} being code for SHIFT+ENTER (syntax may be slightly off)
Logged

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: Scripting, SHIFT+ENTER and 40d9
« Reply #1 on: March 06, 2009, 07:14:46 pm »

From the AutoHotKey help:
Quote
{Shift Down} Holds the SHIFT key down until {Shift Up} is sent. XP/2000/NT: To hold down the left or right key instead, use {RShift Down} and {RShift Up}.

So try something like:

Send("{UP 5}{LEFT}{u 2}{Shift Down}{ENTER}{Shift Up}")
Logged

Sinergistic

  • Bay Watcher
    • View Profile
Re: Scripting, SHIFT+ENTER and 40d9
« Reply #2 on: March 06, 2009, 07:38:03 pm »

From the AutoHotKey help:
Quote
{Shift Down} Holds the SHIFT key down until {Shift Up} is sent. XP/2000/NT: To hold down the left or right key instead, use {RShift Down} and {RShift Up}.

So try something like:

Send("{UP 5}{LEFT}{u 2}{Shift Down}{ENTER}{Shift Up}")

 ;D

What I'm saying is, is that doesn't work. Something is messing up the {shift up/down} stuff, so the game treats the enter that is nested between them as just (ENTER) instead of the (SHIFT+ENTER) it should really be. I've tried it in AutoIt and AutoHotKey. NOTE: This only happens in 40dx, I've not had any problems with 40d not detecting the shift commands.

For example: Lets assume we are in the bC menu, with walls highlighted. we make a quick script that presses (u) nine times, followed by enter, followed by a shift enter. In theory, this will designate 10 walls, build them, and then 'select all' of the first material in the list. HOWEVER, what really happens is this: It designates 10 walls, builds them, and then only 'selects' ONE of the first material on the list, leaving it up to the user to press enter the remaining nine times (or code those extra nine enter press into their script. Which requires more sleep statements, because your sending more commands to the game than you would with a simple shift+enter command)

I want to know if anyone else has had this problem with their scripts, or if it's just me/my computer. And if they have encountered this problem, how they got around it (if they got around it).

I'm not really sure why I posted this in the modding forum :/ (modders ~ programmers = higher chance of someone who scripts seeing this and answering the question?)
Logged

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: Scripting, SHIFT+ENTER and 40d9
« Reply #3 on: March 06, 2009, 08:00:43 pm »

Okay, I just tested this in-game and it worked:

Code: [Select]
; Alt-B  test-build a 5-wide floor
!B::
SetKeyDelay 50, 10, Play
SendPlay bCfkkkk{Enter}{Shift Down}{Enter}{Shift Up}
return

Now you can experiment with the necessary key delay settings and whether it works in regular Send mode instead of SendPlay.

Edit: tested in 40d9 using AutoHotKey 1.0.47.6 .
Logged

Sinergistic

  • Bay Watcher
    • View Profile
Re: Scripting, SHIFT+ENTER and 40d9
« Reply #4 on: March 06, 2009, 10:49:38 pm »

Okay, I just tested this in-game and it worked:

Code: [Select]
; Alt-B  test-build a 5-wide floor
!B::
SetKeyDelay 50, 10, Play
SendPlay bCfkkkk{Enter}{Shift Down}{Enter}{Shift Up}
return

Now you can experiment with the necessary key delay settings and whether it works in regular Send mode instead of SendPlay.

Edit: tested in 40d9 using AutoHotKey 1.0.47.6 .

 :o :o :o :o :o :o

Success! Thank you! /me wonders off to read up on the difference between SendPlay and Send. You've just made writing scripts to build scolding(edit: more like scaffolding) like a billion times easier.
« Last Edit: March 07, 2009, 02:20:16 am by Sinergistic »
Logged

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: Scripting, SHIFT+ENTER and 40d9
« Reply #5 on: March 07, 2009, 03:30:27 pm »

Glad it works for you.

I just want to mention that if SendPlay is indeed required, you should switch to it everywhere.  Mixing Send and SendPlay might result in dropped or out-of-order keystrokes.
Logged