How to detect when screen brightness or system volume changed? - c#

I want to detect when either of these changes and display an overlay on screen showing the current level. If there is a tool for this, then please point me to it. But if not how would I programatically get this (C#)?

The WmiMonitorBrightness class might be what you're looking for. You'll probably need to periodically query it to get changes.

If you talking about the softwares especially for laptops which OEMs like Dell/IBM etc give along with the windows installation to indicate brightness/voulme etc change then try this approach.
Install global message hooks and see what message is posted when volume/brightness buttons are clicked. You can use spy++ to detect the value of the message. In my opinion each vendor would have a different code for the buttons which are generally used along with the Function(Fn) key. Once you know the messages, make an application which installs a global hook for the system and display the animation or level bar as per your requirement.
The WmiMonitorBrightness class is supported for vista and above so if you using Win XP then it might not help you.

Related

On-screen keyboard in Windows Universal App on Windows IoT?

Is it possible to show the On-Screen Keyboard (osk) in a Windows Universal App on Windows 10 IoT Core?
The raspberry pi only has a mouse attached and when I click on a textbox I'd like to show the osk.
I can set the InputScope and IsTextPredictionEnabled but can't figure out how to trigger the osk to show.
There is an example here of an on screen keyboard. If you look at the sample they are using one in their web browser. This is a pretty good keyboard but it would be better to have the default windows keyboard
https://github.com/ms-iot/samples/tree/develop/DigitalSign
If it was up to me I would prefer the default OSK since you can specify slightly different keyboard layouts based on inputs. I don't like this one because the text box loses focus which can limit the use of action listeners that you can use. Hopefully this is something that gets enable in future builds but for now this is a pretty good keyboard you can steal so you don't have to start from scratch.
On a side note you should upvote in Windows Feedback under "Developer Platform/ Windows 10 IoT Core". There should be a suggestion open.
I asked that question back in July on the MSDN forums. The answer that I got was:
"This has been answered here:
https://social.msdn.microsoft.com/Forums/en-US/d81ebfa0-ccdc-479e-8e2f-bc921de17343/onscreen-keyboard?forum=WindowsIoT
There's no onscreen keyboard available at the moment. There's the possibility that one will be added later, but it's not guaranteed. If you read the linked post you also find an explanation as to why none is available."
Just for reference, here's the link to the MSDN question that I asked: https://social.msdn.microsoft.com/Forums/en-US/9c95f424-f0ca-4751-9497-a019c1d40907/touch-keyboard?forum=WindowsIoT
And here's the answer from the linked post:
"At the moment there is no On-Screen Keyboard available. If you want a user to input something via the screen then you’ll want to provide the UI for that input in your application. Part of the reason for this is that we don’t have a ‘shell’ like explorer that is there helping control what app is running or providing other services such as SIP / OSK as is handled on the desktop.
Longer term I believe this is something that the product team is considering / looking into but I do not have any timeline on if or when it might be an option (if ever). If I learn otherwise I will let you know.
I hope that helps."
As mentioned in this answer, if you have the latest version, check On-Screen Keyboard from the Windows Device Portal.
From https://social.msdn.microsoft.com/Forums/en-US/d81ebfa0-ccdc-479e-8e2f-bc921de17343/onscreen-keyboard?forum=WindowsIoT : -
There is one available (I think since 14986). You have to enable it in
the device portal under "Device Settings" > "On-screen Keyboard".
Thursday, January 05, 2017 12:57 PM
I wanted to post the workaround that I came up with, but I didn't have enough rep points yet to include more than 2 links.
So I'm posting it as another answer.
Here it is:
And for those interested, I wrote up a very basic example of a osk-UI element. The Idea was to create something that could be reused if necessary. It's also not the fastest thing but maybe it will give you ideas.
Its basically a UserControl inside a Popup. When a Textbox gets focused, it fires an event that sets the "Keyboard Popup"'s DataContext to that of the Textbox and shows the "Keyboard".
I dropped it into a .zip file and uploaded it to my Box.com account.
Here's the project folder: https://app.box.com/s/vsf1wclaivsan4hhu2u2qdrb2awnbspu

Determining (programmatically) who controls the mouse on a PC using C# or C++

Is there a way to determine who is controlling the mouse (and which mouse) on a PC programmatically? I recently installed LogMeIn (logmein.com) and wanted to know if it's possible to (1) tell within a program if the mouse is being clicked/moved by the direct user or by a remote user, (2) write a stand-alone program that simply shows mouse events (on any application) and whether or not the mouse event was generated by a local or remote user. I am somewhat familiar with Win32 hooks, but don't think that they can give this sort of information. Regarding (1) it would seem like a common request. I.e. "Only allow user to complete button presses related to password change if he is local..." or something like that.
Of secondary importance (just academic interest actually) is the question of telling whether the local user is using the mouse or the trackpad.
you can hook the device API's of windows that you want to get the information from, then if the mouse moves the api is probably not called when the user movers the mouse, but if logmein does then it probably calls some SetMousePointerPos-like C WinAPI.
Since posting, I came across this post which basically answers the question.
C# Get Mouse handle (GetRawInputDeviceInfo)
I'd add that for those of you who want to use WPF instead of WinForms (as the example above uses), check out ComponentDispatcher.ThreadFilterMessage (for WPF) or IMessageFilter (Windows Forms).
I wrote a couple of programs based on the above posting (one is basically the posting above with some minor additions and the other is a WPF (as opposed to WinForms)). If I can figure out GitHub I'll post all the code and add a comment here. But the posting above definitely gives you all you need.

How can i programmatically manipulate the Windows 7 on-screen keyboard osk: Move, Resize, Remove Titlebar/Caption

I'm working on a WPF app where i want to display the built-in windows 7 onscreen keyboard in a 'always there' manner. So i want to:
Move it to a particular location
Set it to a certain width and height
Remove the caption/titlebar so the user can't move it around or close it
Remove that abilty to resize it (or any other user adjustments for that matter).
I've tried all the typical API functions (MoveWindow, SetWindowPos, SetWindowLong, etc...) but it refuses to do anything. Code currently works with all other processes and apps (such as internet explorer and the command prompt); it's almost as if the api calls don't apply to the osk, or that it's 'locked'. What am i missing? Thanks in advance.
I checked with Spy++ and the On-Screen Keyboard uses something called "DirectUIHWND". You may wish to look into DirectUIHWND APIs.
A possibly helpful link:
http://www.codeproject.com/KB/COM/cominterfacehookingpart.aspx
In addition, some people have warned that DirectUI is undocumented.

Multimonitor taskbar in .Net

I have an idea to write a multimotor taskbar application in c# for windows xp. So, does anyone have any information how
to put a taskbar on the second
monitor,
to make it use windows styles,
to prevent aplications running on the
second monitor to appear in default
taskbar,
so on...
Any help would be ...helpful )))
You can P/Invoke SHAppBarMessage() to create a task bar. The APPBARDATA.hWnd you'll need could simply be the Handle of a Form class. Anything goes as far as what you display.
Getting the notifications you'll need to make the task bar display active windows is going to be a whole lot more difficult. You'll need to use the global WH_SHELL hook, set by SetWindowsHookEx() to receive the notifications you'll need. You cannot set this hook in C#, it requires an unmanaged DLL that you can inject into a process. You'll find crucial help in this project.
Getting the Windows taskbar to not do its normal job is going to be impossible unless you somehow find the undocumented information you'll need. Microsoft doesn't document this for a good reason, the taskbar is an important part of the way they innovate on the Windows look-and-feel. Quite visible in Win7. They don't want any code to take a dependency on this, they'd have a near-impossible job of keeping the next version of Windows compatible. I'd have to recommend you completely disable the Windows taskbar and replace it by your own.

How can you read values from an open application in Windows?

I want to create a program or use a program that will read the memory values out of another application. Does anyone know of an application/library that will do this?
The target app is this. I would like to read the exchange rate values from it.
I'm an experienced c# programmer, but have never worked with the Win32/user32 api which is what I'm assuming I'll have to deal with to pull this off.
Any help that gets me going in the right direction is greatly appreciated.
Update:
I managed to use Spy++ to get the window handle, so I'm sure I can get the values some how.
Have you looked into AutoIT or AutoHotKey?
Both of these open source options have well documented abilities to read text from application windows (and send keystrokes or mouseclicks to them).
AutoIT is very easy to use and well documented.
An example of reading text from a window would be:
$text = WinGetText("title of window", "")
MsgBox(0, "Text read was:", $text)
This can be compiled into an executable.
Typically an application creates controls in a dialog in a consistent manor, same ID, same order etc, so finding a control programatically is fairly simple. Using Spy++ find the control's ID and then you can search the windows created by the application for the desired control. Not being familiar with the app in question I cannot give specifics, but if Spy++ shows the value you desire, it is likely not difficult to obtain the value in your code.
What type of control is the value displayed in? You'll may be able to use GetDlgItemText to obtain the value once you have the parent window handle and control ID? To get the parent window try using EnumWindows.
It might be easier to scrape their data by automating a screenshot and then ocr process. If that's your goal.
Potentially relevant links:
get-a-screenshot-of-a-specific-application
ocr-with-the-tesseract-interface
May be this article helps - http://msdn.microsoft.com/en-us/magazine/cc163617.aspx, but I think it's not universal and for your task is better to get access directly to Forex API/Web-Service or try to catch needed data on network.
It is possible to screen-scrap things created with native windows controls; if that is the case, you should be able to see the controls using Spy++. But some times controls are implemented "by hand", and there is no way to screen-scrap them (e.g. some Java graphic toolkits play directly with the graphics, so everything day do is meaningless from the outside, or even some Office menus are implemented without using the menu control).
The Windows accessibility API is a possible way to screen-scrap the values; check if "Narrator", the screen reader that comes with windows, is able to read aloud your target application.

Categories