8 Replies - 9996 Views - Last Post: 13 March 2013 - 10:49 AM Rate Topic: -----

#1 evilC1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 13

WPF application stops processing when not the active window

Posted 13 March 2013 - 09:08 AM

I am totally new to windows programming, C# and WPF, so please excuse me if I use incorrect terms.

I am writing a WPF application that reads joystick values, performs some maths (ie an invert) and controls a virtual joystick via the vjoystick SDK. The purpose is to allow people to invert axes, adjust sensitivity, merge multiple sticks into one virtual stick etc. The user maps the virtual stick to game functions, and the physical stick(s) controls the virtual stick.

I have the code working, however when the WPF application is not the active window (ie it does not have "focus") then it stops processing.

What mechanism would be used to tell the whole application or a subroutine of it to continue processing the joystick input while it is not the active window?

The app will ultimately feature UI elements that reflect the state of the joystick, and it would also be nice for these to update while it is not the active window (ie you can see the window, but it is not the active one) but this is not essential.

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: WPF application stops processing when not the active window

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,362
  • Joined: 02-June 10

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 09:24 AM

That's normal behavior. The program doesn't get the input if its not in focus which isn't unreasonable: Would you want Outlook responding to mouse moves and clicks while you are in a web browser?

Its not that you continue processing the data when not in focus - its that the program doesn't receive the data from the OS.

To do what you describe you'd have to write something at sub-application level; intercepting the driver calls.

You might be able to intercept windows messages. Then you'd have to learn which messages and values are coming from the joystick and what each value means. Basically reverse engineering the driver.
http://social.msdn.m...0d-b47b6becf70d
Was This Post Helpful? 0
  • +
  • -

#3 evilC1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 13

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 09:32 AM

Thanks for the quick reply.
I can totally understand why it would behave like that by default, but was hoping there would be some way around this.
Is this a limitation of WPF? ie if I used C++ or regular C# could I solve this issue more easily?

Also, what you say doesn't quite hold true - for example if I opened outlook and ran a search on all my emails, the search would continue even if outlook wasn't the active application.

The only reason that I picked WPF was that it seemed to offer an easier learning curve than GUIs using regular C++ or C# - the whole idea of handling paint messages and stuff was a little steep a learning curve for my liking. If that is what it would take though, I may have to just man up.

Any advice gratefully received.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,362
  • Joined: 02-June 10

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 09:43 AM

You're having trouble seperating "processing" from "input".

Outlook will continue processing. But Windows stops sending mouse click and move events to it. That's why three programs don't all 'hear' the click event at the same time. Your OS is being the traffic cop for all these Windows messages.

Your game *is* continuing to process.
But the OPERATING SYSTEM is no longer sending input from the joystick to your program. The game is processing the input it gets: Which simply happens to be none.

Coding language is not the problem here. So you won't be listening for paint messages. You have to listen for the messages coming from the joystick.
Was This Post Helpful? 0
  • +
  • -

#5 evilC1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 13

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 10:17 AM

I get you, that makes sense.

I will keep asking about, as I know this has been done a number of times before (XPadder, GlovePIE, AutoHotkey etc).
In fact, AutoHotkey does this and is written in C++. It is open source, I don't suppose anyone who knows C++ could look at the source code and tell me how they work around this issue?
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,362
  • Joined: 02-June 10

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 10:21 AM

Sounds like this just became "gimme teh codez".

Would someone show me how to build my program? - Read this article

We have an area where you can post this as a job for hire. Would you like the thread moved there?
Was This Post Helpful? 0
  • +
  • -

#7 evilC1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 13

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 10:34 AM

Whilst I appreciate where you are coming from, I think that post is not exactly applicable to this situation.

I spent 100+ hours coding the AutoHotkey version of my app ("UJR"), and give it away for free.
There are many people all over the world who use it, but because of writing it in AHK, functionality is limited (eg it cannot support multi-hat joysticks). Hell I don't even use it for anything myself - I wrote it for purely altruistic reasons.
Therefore, I feel no shame in asking for a little help in this regard.

For example, if someone knew C++, and took say half an hour to look at the AHK source code, worked out how to get access to the messages whilst the application was not the active one, then they would have learned something also.

At best, I would be asking for a code snippet - proof of concept code that say played a sound when you hit a key no matter if the app was active or not.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,362
  • Joined: 02-June 10

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 10:43 AM

Perhaps this should go to "Share my Project" and you could move to a more 'open source' design with it so those others can be a part of the project.
Was This Post Helpful? 0
  • +
  • -

#9 evilC1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 13

Re: WPF application stops processing when not the active window

Posted 13 March 2013 - 10:49 AM

I had planned to create an open source project on google code or something, but I was trying to finish the proof of concept code first, as if I could not get the basic functionality working myself, I saw little point in starting the project proper.

At the moment, my proof of concept code is horrific - I have bolted bits of sample code together and it would just cloud the issue I think.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1