Find out which display belongs to which adapter? - directx

I'm working on a SlimDX apps which works for multiple display. The apps will occupy the selected display, and it's selection is input via commandline, as int. I then use System.Windows.Forms.Screen.AllScreens[selection] to find out about the bound, and display my apps "fullscreen" on that display.
Now, to optimize performance, I need to select which gpu adapter to initialize the Direct3D's device. How do I find out which gpu adapter is powering the selected display?
Since Each gpu adapter might have one to two display connected, I can't use the display number.
I'm utilizing Direct3D10. I don't mind solution in Direct3D9.
Worse case would be to let user select display and adapter via commandline, but I prefer a fool prove method.
Thanks

Both D3D10 and D3D11 use DXGI for managing details like this. The Factory interface you create lets you get a list of adapters installed on the system. Each adapter can have one or more outputs, which you can enumerate from the Adapter interface.
This will get you a list of Output interfaces, which have a Description property that contains, among other things, a Rectangle of the output's bounds as well as an IntPtr handle to the monitor on which it is running.
I don't think the Winforms Screen class exposes the underlying native pointer, which is why we provide the SlimDX.Windows.DisplayMonitor class to serve as a replacement for the Screen class. You can use this to determine the particular details of the display and choose the right adapter for your needs.

Related

Reading and identifying multiple USB keyboards

I'm in charge of technology at my local camera club, a not-for-profit charity in Malvern UK. We have a database-centric competition management system which is home-brewed by me in Delphi 6 and now we wish to add a scoring system to it. This entails attaching 5 x cheap-and-standard USB numeric keypads to a PC (using a USB hub) and being able to programmatically read the keystrokes from each keyboard as they are entered by the 5 judges. Of course, they will hit their keys in a completely parallel and asynchronous way, so I need to identify which key has been struck by which judge, so as to assemble the scores (i.e. possible multiple keystrokes each) they have entered individually.
From what I can gather, Windows grabs the attention of keyboard devices and looks after the characer strings they produce, simply squirting the chars into the normal keyboard queue (and I have confirmed that by experiment!). This won't do for my needs, as I really must collect the 5 sets of (possibly multiple) key-presses and allocate the received characters as 5 separate variables for the scoring system to manipulate thereafter.
Can anyone (a) suggest a method for doing this in Delphi and (b) offer some guide to the code that might be needed? Whilst I am pretty Delphi-aware, I have no experience of accessing USB devices, or capturing their data.
Any help or guidance would be most gratefully received!
Windows provides a Raw Input API, which can be used for this purpose. In the reference at the link provided, one of the advantages is listed as:
An application can distinguish the source of the input even if it is
from the same type of device. For example, two mouse devices.
While this is more work than regular Windows input messages, it is a lot easier than writing USB device drivers.
One example of its use (while not written in Delphi) demonstrates what it can do, and provides some information on using it:
Using Raw Input from C# to handle multiple keyboards.

Getting started on custom gamepad handling

Since I find the default gamepad handling of Windows to be lacking, I'd like to write a custom interface for that purpose. Basically, I want to add a layer between the plugged in gamepads and the Windows gamecontroller management. While I'm not sure how to tackle this problem, these are the steps I was thinking off so far:
Disconnect any plugged in gamepads from Windows' gamecontroller management
Create virtual gamecontroller (perhaps with vJoy/pyvjoy)
Read inputs from the plugged in gamepads and apply them to the virtual gamecontrollers
However, apart from the second bullet point I don't know whether (and how) these are doable. Are there any APIs that can interact with devices the way that I need to? Do I need to get into driver programming and rewrite gamepad drivers?
I know this is a broad question to a very narrow topic, but I'm kind of at a loss where to get started. Any help would be much appreciated.
HIDGuardian covers your first bullet point:
https://github.com/nefarius/ViGEm/tree/master/Sys/HidGuardian
HIDGuardian is used by InputMapper to hide the physical gamepad when a virtual gamepad has been created for the device. This prevents applications from seeing input from the same gamepad twice.

Get current used videocard

I am programming a simulation in xna/monogame; but i want to go sure and wanna warn (myself ..( = ) if I use inadventertly my on-board video card..
Do you know any way to solve my problem?
Does the graphicsdevice offer a property to determine current used video card?
Thank you in advance!
During XNA start-up you can create your own custom GraphicsDeviceManager that can rank or choose devices based on criteria you provide.
MSDN:
GraphicsDeviceManager Class
Handles the configuration and management of the graphics device. Custom behavior of the GraphicsDeviceManager can be achieved by deriving a class from GraphicsDeviceManager. For example, to allow only widescreen devices in full-screen mode the RankDevices method could be overridden to drop non-widescreen devices. - Tell me more...
During the call to your RankDevices() method, you can inspect the list of GraphicsDeviceInformation to determine information about the adapter and device.
RankDevices() orders the provided list so that devices earlier in the list are preferred over devices later in the list. This method can remove devices from the list if they do not satisfy some custom criteria. Tell me more
Each GraphicsDeviceInformation object has an Adapter property of type GraphicsAdapter. There you will find such useful properties as:
Description
DeviceId
DeviceName
VendorId
...and many more.
More
The tutorial Restricting Aspect Ratio on a Graphics Device will walk you through the process of controlling what device you get. Once you understand that, altering it to filter based on device types should be easy.

using XInput, is it possible to get an image of the controller?

In my simple mind, it seems useful to ship a nice image of your joystick with an index of the button and axis locations on the image. Can such a thing be queried through the XInput or DirectInput APIs? Would it be driver-specific, and if so which drivers support this?
In particular, I want to support Logitech wheels and XBOX 360 controllers. The Logitech Profiler seems to come with this information (or pull it from the driver). Is it accessible in my code as well?
I see the image of the joystick show up in the game controller properties, but I assume that entire property page is reported from the driver?
XInput does not supply this and it is not supposed to, XInput is an interface for accessing the state of the controller and the capabilities of the controller. This is something that you would detect manually in your code, finding the correct device id and I believe this is what the Logitech Profiler does as well (since it is a custom application for Logitech), it simply has the images as resources in the program itself.
What is commonly done is that you contact Microsoft, Sony, Nintendo or Logitech and they will have high quality images of their controllers that are approved for use in games. Specifically for images of the controller in console games there are certain requirements that you need to follow. The same requirements do not follow for games for windows and other operating systems but you should still be able to retrieve this information from Microsoft and Logitech.
By retrieving the resources yourself you can also convert them to a format that suits the interface where you are presenting them.
Since the Windows XInput API was created specifically for the XBox 360 controller, it's possible to make a great deal of assumptions about the controller layout. Even now, after the release of official drivers for the XBOne gamepad, the official API documents go out of their way to explicitly limit discussion to the 360 pads.

Binding a trackball to NPAPI

I want to use a second pointing device (the trackball) as a control for a specific function on a program. This means I would NOT want any mouse functionality from the trackball, I just want to get the movement data and somehow use the NPAPI to get that into our web app. Is there a way to bind a mouse/trackball to a specific program that it doesn't act as a mouse/trackball for the computer?
Thanks in advance!
UPDATED: actually ask a question
To the best of my knowledge and my understanding of how HID devices work, there is no way to do what you want to do. If you could do it at all, you could probably do it from an NPAPI plugin, but there is no way to tell the operating system not to take control of one specific pointing device as opposed to any others.
Now, if you had a special HID trackball that didn't show up as being a regular pointing device then you could possibly do it with that, but I have never heard of any way to take control of just one of potentially many HID pointing devices on windows, linux, or mac.
There may be a way to hack something together in Linux by changing the way the drivers work, etc, but I don't know of any.

Resources