Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

C# / WPF etc - receiving input while not active window


  • Please log in to reply
2 replies to this topic
evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

It's maybe a little cheeky posting on here - I am trying to re-write an application I wrote using AHK in C#, C++ or some other similar language.

 

The application is a joystick remapper - a physical joystick is read, operations performed on an axis (eg an invert) and the output is piped to a virtual joystick via the vJoystick SDK.

 

I have proof-of-concept code working using the SlimDX library in WPF using C#, however when the application is not the active window, it stops working.

 

I have been told that this is not a trivial thing to solve and that the OS is not sending the input info to the app while it is not the active window, and that switching to regular C# or even C++ is not going to easily solve this.

 

The reason I am posting here is that I guess coders of AHK know how to work around this issue, so I wondered if anyone on here may be able to offer any gems of information.

 

Disclaimer: What I know about C++, C#, WPF and windows programming in general could be written on the back of a postage stamp, so if possible keep replies in layman's terms as much as possible...



IsNull
  • Moderators
  • 990 posts
  • Last active: May 15 2014 11:56 AM
  • Joined: 10 May 2007
The language doesn't matter as long as it gives you access to the WinApi.
For low-level stuff like this, C# is definitely your last choice.

So you will end up using SendMessage, or in AHK Terms "ControlSend" may also work.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

It's been a long time since I've worked with joystick input in C#, but IIRC, this problem was very easily overcome with managed DirectInput by simply calling the Device.SetCooperativeLevel method with the Background and NonExclusive flags.  I believe the unmanaged interfaces have an equivalent function.

 

AutoHotkey calls simple Win32 functions like joyGetPosEx, which probably doesn't care which window is active.  IIRC, the limitations present in GetKeyState (e.g. maximum number of buttons and axes) directly correspond to limitations of this API.