1

So I know there are a lot of threads regarding this topic, but i can't seem to understand what people are talking about when they copy/paste a huge block of code and say "here try this". As an amateur programmer, that doesn't help me at all. So will someone please explain this in depth to me?

I am creating a third-party background application using Windows Speech Recognition for the game Smite by Hi-Rez Studios. For those of you that don't know about Smite, it has an in-game "quick ping" system. You press V to activate the system, and it comes up with a list of commands that you can use with further keys (for example "V, A, A is the command for "Attack" and V, A, F is the command for "attack fire giant"). Using the voice recognizer to detect when a command is spoken, it does a basic SendKeys command like this to emulate the keystrokes:

SendKeys.Send("vaa")

However, this code can also execute while other programs have focus, such as Notepad. I don't want this to happen. I want the SendKeys ONLY when Smite is the active window by running some sort of check to confirm that Smite is the active window before doing the SendKeys.

Can someone please explain to me how I would go about doing this? I would like to learn to do this rather than relying on the online community to provide me pieces of code that I copy and paste.

  • Have you done any research into finding the active window? It's not hard to do, and has [been covered before](http://stackoverflow.com/questions/22201752/how-to-get-active-window-app-name-as-shown-in-task-manager) here on Stack Overflow. Beyond that, the [MSDN documentation](https://msdn.microsoft.com/en-US/) has a vast library of documentation explaining these things, including the likes of [`GetForegroundWindow`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633505%28v=vs.85%29.aspx) which is being used in the linked question. – James Thorpe Feb 09 '15 at 17:09
  • `SendKeys` has proven to be an unreliable mechanism for this kind of work. – OneFineDay Feb 09 '15 at 17:11
  • @James Thorpe Yes, I've done research (or at least tried) and none of it makes sense to me. I read through both of the links you provided and nothing i saw made much sense to me except a little bit of code, and that only provided me a general direction to go in and did not explain to me what exactly i needed to do to go there. I would like for someone to explain, not redirect. – Tanner Fix-It Smith Feb 09 '15 at 20:38
  • @OneFineDay Why is it unreliable? I've had no problems with it so far. What are some issues i may encounter? – Tanner Fix-It Smith Feb 09 '15 at 20:38
  • @TannerFix-ItSmith Unfortunately it then sounds like what you're asking for essentially falls under the "Too Broad" off topic category - the (current) intention of SO isn't to provide complete tutorials on such a wide ranging question or lengthy introductions to topics such as this – James Thorpe Feb 09 '15 at 20:43
  • @TannerFix-ItSmith, I have tested it with multiple calls and not all go thru - maybe a speed related thing. Glad it seems to be working for you. – OneFineDay Feb 09 '15 at 20:51
  • @OneFineDay Well, each call is used through a Select Case tree, with each Case corresponding to a command. Maybe the problem is that (if youre emulating multiple keystrokes) using SendKeys twice in rapid succession overlaps the keystrokes? – Tanner Fix-It Smith Feb 09 '15 at 21:37
  • @JamesThorpe I see. Well, I'll edit the question accordingly. – Tanner Fix-It Smith Feb 09 '15 at 21:38
  • I am just saying there is a better way - [Windows Input Simulator](https://inputsimulator.codeplex.com/releases/view/37570)! – OneFineDay Feb 09 '15 at 22:48

0 Answers0