Archive: console app question


console app question
  Situation is, I want to include a console progie to my installer (nsis is the best :)), however it has one anoying (in my case) feature - to quit it you have to press enter-key (i guess it was implemented to let a user see output or something). This proggie works several times during install, and each time user would have to click enter - and that's pointless and irritating.
Is there some way around this, like emulating a key-press? Terminating a dosbox is not an option, I tried it and it messed up the proggie's work.

PS: I realise that my question is not quite related to NSIS, but I didn't know where else I could ask, and I see lots of experienced people here, programmers and such... :cool:


You could try using

FindWindow $0 "Your Window Title"
SendMessage $0 ${WM_KEYDOWN} 13 0
(note you have to include WinMessages.nsh to define the WM_KEYDOWN variable). This should send a return key press to the window (13 is the ASCII value of carriage return). (this might help give you an idea of how SendMessage can be used)

Alternatively something like AutoIt can be used to control applications using key presses and mouse actions.

I think nsExec can also help you. As it runs the console application "inside" NSIS it can't get any output so it won't do nothing when the user presses enter.


Thanks for the input Sunjammer!

Tried that AutoIt thingie, it's cool, never thought such tool existed :up:. It managed to emulate pressing return. But I wasn't totally pleased with the result, to do it the perfect way I'd have to spend time learning it's commands, and frankly I'd prefer to spend that time learning nsis :). Plus it adds another exe to my install.

So if you said that it's possible to do it with nsis, that would be so much better. And I'll use AutoIt only as a last resort. :) Anyway, I tried to use the code you gave, and it didn't work out.

FindWindow$0 tty // FindWindow $0 "" "nop_up" also worked

>SendMessage $0 ${WM_KEYDOWN} 13 0
>
code above produces some weird sound from pc-speaker (!?), then writes one random symbol to dos-box - so it kinda gets to work: it finds the right window, and writes to it, but not enterkey.
And out of sudden, sometimes it does nothing at all, sometimes it screws-up the dos-box and one time it even screwed-up keyboard and mouse - they started to work incorrectly. :confused:

btw, from silliness at first I tried looping it, something like:

loop:

FindWindow $0 tty
IntCmp$0 0 done
IsWindow$0 0 done
SendMessage$0 0x100 13 0
Sleep 100
Goto loop
done:
and it worked the same, continuously making eeck-sounds from speaker, writing crap to dos-box and eventually freezing my pc. :mad:
Kids, don't try this at home! :D

WTH? Any ideas? Note that I have no experience in programming of any sort, and started to use nsis recently. But I'd really like to get it going. :cool:

TIA,
galil

I've just got home (2am here :D) -- I'll try to look at this for you tomorrow morning at work if I can.


Ignore what I have said, it does wait for enter (at least for makensis).