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.
Related
I have developed an application in C++ that runs on Windows 7, 8.x and 10. I would like to use a Bluetooth remote shutter to control the application.
The remote shutter seems to be a HID device that sends keypresses to Windows. The default behavior of those keypresses is Volume Up, Volume Down, Play/Pause, Next and Previous.
While I can detect those keypresses from my application and act on them, I have not managed to disable Windows acting on them. E. g. currently, when someone presses the Volume Up key on the remote shutter, two things happen:
Whatever I tell my application to do on that keypress
Also, volume goes up on Windows
How can I tell Windows not to act on those keypresses for this particular device?
Thank you
I have not tried it but i think it may be possible by disabling the Human Interface Device Access Service on Windows.
There may be some side effects along with that like for example:
If the service is stopped or disable, the buttons on USB keyboards will not function (i.e., back, forward, volume up, down, previous track, next track), nor will the volume buttons on USB speakers.
but you can still try :)
here is how to disable it
I am having a propertysheet application and I am doing some operation in it and now in the middle
I restarted my machine then all the applications or closed including my application.Instead of
forcely closing my application I want to make my application to support something similar to this when I press restart.
Exactly I should make application support same feature as in the above image.
Can anyone please let me know how can I solve this issue.
From MSDN: The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.
You can handle this message in your main window. If there is no MFC macro for this message you can use the ON_MESSAGE macro in the message map.
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.
I have used the template provided Here, to create a windows service. I would like to use this service to reset the system idle timer to avoid the OS going to sleep mode.
SetThreadExecutionState, seems the be the right way of doing so. However, it appears that this method, does not work when the program is running as a service. I have even tried sending an event with keybd_event function, but it appears that there are some security measures in place (see question No. 12747430), to filter out mouse/keyboard events for non-desktop applications ( Even though 'Allow service to interact with desktop' option, is checked for the service).
So here's the question: How can i reset the system idle timer through a windows service? (should not be dependent on user's desktop and should work on login screen as well)
PS: the OS is windows 7 x64
Thanks in advance
How Can I execute a function when Windows shutdown. Here is my scenario, I am mounting a drive using WNetAddConnection2 function in my application. Now I want user to set the option if the drive will be mounted on next system startup or not.
If he selects , not to mount on next startup , then I need to remove the drive using WNetCancelConnection2 , but this should only happen when user shutdown the system.
I can only think of only solution. Create a service which will check the user option and then decide whether to mount the drive or not.
Are there any other ways to go ahead with it?
If you have a main window (even an invisible one) that can process messages, you can handle the WM_ENDSESSION message.
See: http://msdn.microsoft.com/en-us/library/aa376889(v=VS.85).aspx
If you can make your app into a Windows service (or have your app communicate state with one that you provide) you can perform required actions on receipt of SERVICE_CONTROL_SHUTDOWN in your service control handler function. This would decouple your app that handles user interaction from the shutdown handling, which requires something to be running all the time (what if the user logs off?).
explorer.exe is the GUI process of windows which usually only gets shut down if Windows shuts down (exceptions have to be made for certain error conditions). You could listen on the WM_DESTROY window message for the process ID of explorer.exe and dismount then.
The way I can think of is to:
Register your program to auto Start up (when PC starts). Here's a tutorial on howto.
Store the user option (as mentioned above) in a repository or registry (if you know how). When your app would have started, you can read your registry and act accordingly.
For shutdown, your application will have to hook itself on a SystemEvent to detect shutdown (then you can act accordingly). Here's an example on howto (C#). For C++, you can listen to WM_ENDSESSION message.
I hope that my 2 cents can help you.