Click here to Skip to main content
14,237,088 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys!

I saw the news article today about the "Twitch Plays Pokemon" and it made me curious to see if I could write a C# program where I could type commands into a text box and control a character in an emulator. It's something I've never tried to do before and it seemed like an interesting challenge.

Well, I've spent quite some time on it and I'mm reasonably sure that I have the SendKeys commands working right but it refuses to work with VisualBoyAdvance.

http://pastebin.com/wr9t339g[^]

I have a feeling it's because the correct child handle isn't being focused. However, in every test I've done it refuses to give me a list of child handles. It's as if there are none. I don't have Spy++ (express edition doesn't have it) but WinSpy does sort of confirm that there are no child handles (that I can see on it anyway).


Any help is much appreciated in this as I'm about to go crazy.


[edit]unnecessary code block removed and clickable link[/edit]
Posted
Updated 15-Feb-14 7:58am
v3
Comments
Sergey Alexandrovich Kryukov 15-Feb-14 21:13pm
   
Of course. SendKeys is nothing serious and hardly should be used for anything. Often used by sloppy UI developers, instead of using legitimate techniques. Better forget it.

If you have some concrete goal which you can clearly explain, probably we can help you.

—SA
Member 10599065 15-Feb-14 23:26pm
   
They say imitation is the best form of flattery.

There's a news article and a Twitch.tv stream going around the internet (link to article here: http://www.polygon.com/2014/2/14/5411790/twitch-plays-pokemon-creator-interview-twitchplayspokemon ) where some guy used Python to write a way for his twitch viewers to control a gameboy emulator using the chat. So people in chat would type something like "UP" and the program would take that and tell the emulator "UP" so that the character on screen would move upwards.

I'm not trying to take his fame or copy him outright, I just thought it'd be a fun little project to write a C# version that worked with the Gameboy Advance emulator "VisualBoyAdvance" (or, alternatively, a GBA emulator named BoycottAdvance).

Basically, at this point, I'm not even thinking about "multiple people" inputting commands at the same time. Right now I'm more interested in just taking a quick console app (see the pastebin I posted) and converting a command, like typing "UP" or "START", and having it send that command to the emulator and acting as though the player of the game has pressed up or start. Later on I'd like to convert it to work for IRC, just as a simple test (I have no interest in running a 24/7 stream and allowing thousands of people to try to play a game, I'm more interested in seeing the _HOW_ of this and getting a working model, as the guy who originally did the Twitch thing isn't releasing the source code to the public).

I hope that helps clear it up a little bit.

Right now I'm trying to do it with SendKeys but if there's a better way to do it, please let me know as SendKeys isn't working at all with VisualBoyAdvance and only about 50% of the time with BoycottAdvance.
Bruno Amancio Dos Santos 19-Feb-14 1:09am
   
I'm trying the same thing and have the same issues. Have you solved it? I can't make the game recognize the key events, just the top menu. If you set commands like UP and DOWN with a menu selected on top it will work there, but not in-game. Take a look at my post on http://stackoverflow.com/questions/21871323/controlling-third-part-application
EveryNameIsTakenEvenThisOne 20-Feb-14 2:58am
   
I got the same issues, however I fixed them after multiple hours of confusion! Add me on skype: fuzionxt

We might be able to work together and improve it more :) (thats also for everyone who comes across this by google)
snaketrm 21-Feb-14 6:52am
   
Same problem here, i can send inputs to the main window but not to the game.
Tried with VBA and Snes9x, no luck. SendKeys and SendInput doesn't work :(

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can simulate input using the raw Windows function SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

Unfortunately, using it would require P/Invoke, but everything is already done for you: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

It does work in a universal way not depending on the nature of the UI and is even pretty easy. In this respect, you can consider that SendKeys does not work at all. Just forget it. :-)

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100