how to determine keyboard disconnected in DirectInput - c++

I am monitoring HID connections using EnumDevices(..., DIEDFL_ATTACHEDONLY). When I disconnect a game controller it no longer shows up in the callback. However, when I disconnect the keyboard, it still shows up in EnumDevices.
I've looked through the API, but I don't see where else to query if a device is connected.

What about http://msdn.microsoft.com/en-us/library/windows/desktop/aa363432%28v=vs.85%29.aspx
You can subscribe to any device notifications like attach,detach,etc...

Related

How to trigger mouse and keyboard event programmatically in Windows 8?

I am trying to develop a program so that I could use my android phone as mouse. For that i will have a service running on Windows pc which will wait for packets from android phone through socket connection. These packets will contain information about the mouse events like button pressed, position etc. I want to dispatch the event in the system. How would I do that using C/C++? Thanks in advance.
Use the SendInput function to generate simulated keyboard and mouse events.
If you are going to create an actual NT service then you might have a problem because the service will be running in the wrong session. If you still feel you need a service then you might have to spawn a new process that runs as the user in each session with CreateProcessAsUser but it is much simpler just to design it as a normal program that starts when a user logs in by adding a Run registry entry.

ASIO - Detect dead connection

I am trying to create an asynchronous server in C++ using Boost ASIO library, it goes by standard model provided at their webpage, ioservice and worker (session)
I am using something like this:
asio::async_read(socket,buffer(data,datalen),[=]( error , len ){
if(error || len==0) disconnect(); else processRequest(data,len);
})
Firstly, it works just fine, when user opens and closes connection - OS does the job.
But problem comes when user disconnects from internet by force, socket remains in "ESTABLISHED" state, though user is already gone, yeah, how would OS handle sending TCP close packet, when internet is not available anymore?
Also problem comes with telephony internet networks, user travels, switches zone from HSDPA to no internet and finally GPRS, old HSDPA socket remains "ESTABLISHED", though user already doesn't use it.
How to detect dead connections like this?
When the client application closes the socket your read handler will be called immediately
When the client application crashes but the client OS is still online your read handler will be called after the client OS timeout (one minute or so)
When the client computers cable is unplugged there is no notification at all. You can implement a keep alive mechanism at application layer or use the TCP built-in keep-alive. I'd recommend to do your own as you have more control (e.g. reconnect a session). In principal you do an async_write which would result in your write handler being called with an error.

mouse_event block on explorer.exe

Am developing a remote access application, like teamviewer. Where i will be sending mouse events from client to server (executed at server using mouse_event() function). But for some reason mouse events are blocked, server is able to receive them and post them to OS using mouse_event() api, but there is no result.
Is there any tool to check, why OS has not executed these mouse events.
Note: Key board events work well and good. And i tried SendInput() api also.
Am developing the application using C++ on windows.
Please let me know your suggestions on the same.
Thanks in advance,
Paul.

HDMI Connection Does Not Send WM_DEVICE_ARRIVAL Message

I am attempting to detect when my TV is connected to my laptop via HDMI cable. I am using the WinAPI function RegisterDeviceNotification() to handle device messages.
When I connect my TV to my laptop (via HDMI cable) I never receive a WM_DEVICE_ARRIVAL message, only 3 WM_DEVICE_CHANGE events. Is this normal?
I really need the WM_DEVICE_ARRIVAL event because the lParam(or wParam, I forget) contains a structure that tells me the type of device connected and the device name whereas, afaik, the WM_DEVICE_CHANGE event does not contain this structure.
If its normal to not receive a WM_DEVICE_ARRIVAL message upon HDMI port insertion, what other method could I use to determine the devices name and type when its connected?
My only idea is: list all devices upon application startup, upon device connection react to the WM_DEVICE_CHANGE event and see if the list of devices has increased.
You could poll GetSystemMetrics(SM_CMONITORS) or EnumDisplayMonitors.
The WM_SETTINGCHANGE message is (usually) sent by applications and services which change system metrics, including the desktop resolution (which changes when HDMI is plugged if the desktop is extended, it wouldn't for mirroring). You could use this to trigger the above polling, instead of relying solely on a timer.

Detecting FireWire cable event within MFC C++?

I'm trying to detect the event when a FireWire cable is plugged into the FireWire port of the PC withing MFC C++ app. I would also like to trigger this even myself as the FireWire connections drops and never is rediscovered withing unplugging the cable and plugging it back in.
Anyone have any experience trying to programmaticaly simulate a unplug-replug event?
You can register yourself to receive device arrival messages. See the help for RegisterDeviceNotification to find an example on how to register yourself.
You can trigger a bus reset notification on the firewire bus, but I don't know if you can do this from user mode, without the help of a kernel mode module.