LOGO
General Discussion Undecided where to post - do it here.

Reply to Thread New Thread
Old 04-06-2007, 10:40 AM   #1
CializCialiscsqw

Join Date
Nov 2005
Posts
395
Senior Member
Default Programming/scripting question
What VB are you talking about? Visual Basic, VBScript or Visual Basic for Applications?

The simplest way I can think of is by using the SendKeys function. I'm not familiar with Civ4, but I think that should work. I did something like that for Civ2 anyway.

Write a program where you can select the game info from a list, say. It will then launch or activate Civ4, and navigate to the correct menu and type in the necessary text by sending keypresses.

I'm not sure how to do it with that program running in the background without actually having to change focus to it while you're pressing the keyboard shortcut.


Another way I can think of is to find the location in memory where Civ4 stores this information and directly write it to memory.
CializCialiscsqw is offline


Old 04-06-2007, 03:00 PM   #2
Rexaviennatutr

Join Date
Oct 2005
Posts
569
Senior Member
Default
Originally posted by Mercator
What VB are you talking about? Visual Basic, VBScript or Visual Basic for Applications?
Visual Basic and/or VBA, I know both. I don't know VBScript but it sounds like it's not too hard to learn from what i'd read up yesterday.

The simplest way I can think of is by using the SendKeys function. I'm not familiar with Civ4, but I think that should work. I did something like that for Civ2 anyway.

Write a program where you can select the game info from a list, say. It will then launch or activate Civ4, and navigate to the correct menu and type in the necessary text by sending keypresses. This sounds exactly right, actually ... the rest of the stuff was in case this didn't work.

I notice MSDN mentions that it has a risk in international keyboards of doing unpredictable things - is this because it sends an interrupt basically, or is it okay as long as we're sticking to numbers and letters, and not #$^% type characters? I worry a bit since if I write this I expect international people to probably use it... but perhaps it can be modified in some way (or recompiled by an international keyboard user of whatever type is needed).

I think FindWindow would work fine for me in terms of activating the application... actually found a MSDN page that describes this very well, it uses a program to send input to the calculator, which is roughly identical to what i'd be doing.

I still have to figure out how to programmatically launch a program (since this would be useful also to be able to launch civ4 from this program), but that's probably a lower priority issue than using sendkeys.

Thanks!!
Rexaviennatutr is offline


Old 04-07-2007, 08:58 AM   #3
eocavrWM

Join Date
Oct 2005
Posts
520
Senior Member
Default
Originally posted by snoopy369
I notice MSDN mentions that it has a risk in international keyboards of doing unpredictable things - is this because it sends an interrupt basically, or is it okay as long as we're sticking to numbers and letters, and not #$^% type characters? Well, SendKeys just mimics typing. I think you'd only get into trouble with things like accented letters and special symbols that are on keyboards these days.

I still have to figure out how to programmatically launch a program (since this would be useful also to be able to launch civ4 from this program), but that's probably a lower priority issue than using sendkeys.

Which version of VB do you use? I'm only familiar with 6. Well, actually, it doesn't seem to matter much in this case. I mainly used the AppActivate and Shell functions. They work well enough.

I didn't know VB did threading, and I have no idea what LoaderLock is I'm afraid... Most of my delays were in seconds. So I just used a timer and DoEvents. But VB.NET doesn't have DoEvents anymore it seems.
eocavrWM is offline


Old 04-08-2007, 02:00 AM   #4
payporanymn

Join Date
Oct 2005
Posts
444
Senior Member
Default
Ahh, AppActivate works the same way as the FindWindow roughly, except FindWindow has slightly more complex error checking ability I think. Shell though would be very useful for me because it would permit me to run Civ4 from scratch (though I'd have to figure out how to "wait" for it to load before doing other tasks, which I don't exactly know how to do except to wait for a specific amount of time... which varies between systems and even between startups based on cached or not, HDD spinning or not, etc. ...
payporanymn is offline



Reply to Thread New Thread

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

All times are GMT +1. The time now is 10:28 AM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 PL2
Design & Developed by Amodity.com
Copyright© Amodity