I'm writing a windows 8 desktop app for the tablet that tracks the bluetooth radio status in order to monitor power consumption. Basically, I want to find out the initial radio status, as well as receive callbacks whenever the status changes. I've looked through the MSDN bluetooth functions (http://msdn.microsoft.com/en-us/library/windows/desktop/aa362927%28v=vs.85%29.aspx) but haven't been able to find anything about the event callback.
Can someone please point me in the right direction? Is there a way to do this (preferably in C#, but C/C++ is fine as well)?
Thank you
I think there is no Bluetooth event regarding radio removal. You will be able to use the general hardware events to see device removal, that set-up by function RegisterDeviceNotification. See e.g.
http://msdn.microsoft.com/en-gb/library/windows/desktop/aa363431.aspx
http://www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal
Related
I am trying to dynamically enumerate the drive letters of USBs as they are connected to my Raspberry Pi running Windows 10 IoT Core.
It is my understanding that I can use Windows.Devices.Enumeration.DeviceWatcher or DeviceWatcherTrigger to do this. Once a USB is detected I also want to be able to see if it is empty or, if it isn't, scan for whether it contains a file in a specified directory.
Any help would be greatly appreciated.
Yes, use Windows.Devices.Enumeration.DeviceWatcher to enumerate the portable storage devices on-the-fly, just listen to the Added/Removed/Updated event of DeviceWatcher shall be good enough.
A good tip is if you want to listen to the event in the background(aka, when the foreground app is suspended, you need to handle the Added/Removed/Updated event in a separate windows runtime component, and register the background watcher with Add/Remove/Update event triggers.
Refer to the DeviceEnumerationAndPairing demo project on github for code samples.
Is there some event or notification I can receive or hook each time an external LCD monitor is plugged in or unplugged from a laptop running Windows 7?
The laptop detects this and switches my display to the external screen and back with certain kinds of resizing or repositioning but is this exposed by the operating system so that applications can provide a handler, attach a script, etc?
If not, is there a registry setting or API I could poll from time to time?
(I prefer programming C + Win32 API)
UPDATE
Mike's answer below, WM_DEVICECHANGE led me to RegisterDeviceNotification(), but I'm struggling to implement it so far...
UPDATE 2
This question has been asked with different wording a couple of times, but not fully answered yet in my opinion:
How to detect hot plugging of monitor in a win32 application?
Getting an event on monitor hotplug for windows
According to this article Windows sends the WM_DISPLAYCHANGE message when display resolution changes and also when a display is added or removed.
If you need to react to desktop size changes due to monitor addition or removal, you can do so in the handler of this message. The LPARAM gives you the new resolution of the display on which the window is located. Notice that this resolution will be scaled if you use anything else than 100% for system DPI scaling and your program is not DPI-aware.
Alternatively use the EnumDisplayMonitors function to get the display resolution for each connected monitor and the relative positions of the monitors in the virtual desktop. This functions uses the real device pixel values regardless of DPI scaling.
You can try WM_DEVICECHANGE. If that doesn't do the trick, run your window and attach Spy++ to it which will log all the window messages it receives. Then plug your monitor in and check if you received any messages.
Alternatively you can poll GetSystemMetrics() with SM_CMONITORS.
As said here:
You will see registered messages "UxdDisplayChangeMessage" and "HotplugDetected" (second one only when adding monitor). You can use RegisterWindowMessage to get the identifier for these messages.
There are also other messages you can check, just see the linked answer.
I have a USB 2.0 LED backlit keyboard which continuously has it's LED's on. Unfortunately, the only way to turn off the LEDs is via hotkeys that require a special FN keyboard key (which isn't accessible via keybd_event API or sendkeys class).
Hence, I'd like to make a Powershell script which either disables or suspends/sleeps the USB port for the keyboard (without reboot) after the keyboard and/or mouse has been idle for 15 minutes or longer.
I know there's a USB selective suspend Windows power-saving feature; however, I'm not sure if I can manually do this via script/code for a specific USB port. If it's not possible, I'm hoping for any other possible way to do something similar or just disable the port/device (without reboot).
I did some Internet searches; but the only thing I could find was how to disable the entire USB hub.
If this is something that can't be done easily via Powershell/Win32 API, then I would like to know how to do it via .NET/C#.
Thanks in advance!
I want to detect when my touchpad is clicked!
I normally use a usb mouse, so I don't use the touchpad for anything. Instead I'd like to make it possible to perform an action in .NET, when the touchpad is clicked. This way I can use it as a shortcut: One tap and something cool happens.
Is this possible, and if yes, any clue how? I'd prefer if it could be working in VB.NET or C#.
My theory is that I'd have to make a mousehook, which then somehow determines which device the click is coming from. If the click is determined to be from the touchpad, then cancel the click and doWhatever().
Thanks!
* EDIT *
Well, it's "solved", sort of :) In a odd coincidence, Synaptics released their latest driver and software for their touchpads a few days ago with some new functionality. As my laptop has a synaptics touchpad, I tried out the software and interestingly enough, the functionality for designating clicks on the trackpad to perform an action, was built-in.
So the desired function has been achieved, without a line of code (my own code anyway :).
Answer goes to Adrian though for the link to the RawInputSharp library. I tinkered with it yesterday, and I'm 90% sure it would be possible to use for this purpose, in the event a laptop doesn't have a synaptics trackpad.
Have a look at the RawInputSharp library from this page. It uses pInvokes into User32.dll to get hold of input device information. Using it you can detect which device (ie. mouse) input is coming from.
Having had a little play with it, I managed to extract some code that displays just the device id - a different value depending on whether I use my USB mouse or my internal touchpad. The tricky thing would be to identify which device id is that of your touchpad automatically, but you could manually configure this in your application.
I'm currently working on a project that utilizes a proprietary PCMCIA radio card to communicate with some wireless devices. I currently have a background process that handles reading data to and from the card and storing it for processing, but I'd like to be able to shut down power to the card when my application is not running. I've done some investigating, and while WMI evidently does support the CIM_PCMCIAController profile in its WIN32_PCMCIAController implementation, the SetPowerState() and Reset() functions are not implemented. Does anyone know of a way (with or without WMI) to control the power state of the slot? I need to be able to programatically both power off and power on either the slot or the card.
Edit
Several people I've spoken to have suggested adding a function to the card that would facilitate this. Unfortunately modifying the card to provide this sort of functionality really isn't an option right now.
Edit 2
I've confirmed that the device does show up in the Device Manager under the "Multifunction adapters" category, though neither disabling the device nor the PCMCIA controller itself from here has any effect on the power of the card.
Presumably, the device has it's own drivers of some sort and shows-up in Device Manager.
In which case, you could disable the device by calling devcon (Command-line equivalent of Device Manager), from inside your program. This would make windows handle shutting down the device.
devcon disable. See Example #31 for an example of how to shutdown device by a specific device id.
Am I going on the right-lines, or have I misinterpreted your question?
I'm curious, but does using the "Safely remove hardware..." button turn off the power to the device, enough to satisfy your requirement?
If that works, you could programatically register and unregister the device through Microsoft's API. Here is a page that shows a couple functions that might be helpful for this scenario: http://msdn.microsoft.com/en-us/library/aa363234(VS.85).aspx