I am working on an automated testing library, and want to simulate mouse and keyboard inputs using the SendInput Win32 API. This API allows one to push several input items in a single call to the API. There are a number of other examples and similar libraries throughout the web using SendInput. Many of them pass a single input operation for each call to the API. Is there any advantage to batching inputs, or using a single input per call to SendInput? The documentation doesn't seem to offer guidance, or perhaps I'm misreading it.
There's no real benefit to one technique vs the other that I know of. In either case, the usual potential problem with SendInput is that the input focus could change between when you send the input and when the input is received by the target application. The classic example is a modal dialog appearing asynchronously to alert the user of some problem, and ends up stealing focus, and soaking up the remaining input that was supposed to go elsewhere. There's no difference between doing a successive series of SendInputs vs a single SendInput in this scenario.
(I'm pretty sure that internally, SendInput is just looping over the inputs passed to it anyway...)
Related
I am taking my first dives in to the WASAPI system of windows and I do not know if what I want is even possible with the windows API.
I am attempting to write program that will record the sound from various programs and break each in to a separate recorded track/audio file. From the reseacrch I have done I know the unit I need to record is the various audio sessions being rendered to a endpoint, and the normal way of recording is by taking the render endpoint and performing a loopback. However from what I have read so far in the MSDN the only interaction with sessions I can do is through IAudioSessionControl and that does not provide me with a way to get a copy of the stream for the session.
Am I missing something that would allow me to do this with the WASAPI (or some other windows API) and get the individual sessions (or individual streams) before they are mixed together to form the endpoint or is this a imposable goal?
The mixing takes place inside the API (WASAPI) and you don't have access to buffers of other audio clients, esp. that they don't exist in the context of the current process in first place. Perhaps one's best (not so good, but there are no better alternatives) way would be to hook the API calls and intercept data on its way to WASAPI, if the task in question permits dirty tricks like this.
I got stuck at this basic matter.
I can't find any other way to obtain input but through CoreWindow class (handling KeyDown/KeyUp/PointerMoved events or calling GetKeyState in the loop).
I thought that I had to deal with input device directly, but it turns out that interactions with generic HID devices are blocked for UWP applications.
There is also a "low latency" sample among UWP samples, that uses some twisted method through creating dedicated XAML control, but it seems more like a method to coexist with XAML rendering loop while I'm dealing with non-xaml application.
Maybe someone knows a good workaround for this?
I am writing an application in C++ in windows, that has a UI (WxWidgets) and user normally use the application via its UI.
Now I have a new requirement, the application needs to start and controlled by another application.
I can not develop a DLL or similar solutions.
I have access to my code (apparently!) and the other applications is developed by other users, but I can give them details on how to control my application.
My question is: How can I allow other applications to control my application via a defined interface?
For simplicity assume that I developed a calculator (has UI) and I want to give other application to do math on my application (for example they may ask my application to add two numbers and so on, As the math is very time consuming, I need to inform them about progress and any error that generate during processing.
Can I open a pipe to communicate?
Any other way to achieve this?
You can use pipes or tcp/sockets with a custom protocol, but probably it's better if you split your application in two parts:
One part that does the computation
The user interface
and publish the first one as an http server responding to JSON requests.
Using a standard protocol can ease up testing and increases interoperability (you can also probably leverage already existing libraries for both implementing the server and the JSON marshalling).
Note that in addition to accepting commands, any error message you are going to show for example in a message box or any other nested event loop like dialog boxes need to be rewired properly; this can be very problematic if message or dialog box come up as the result of calls to external code that you didn't write yourself.
This is the typical change that would have costed 10 if done early and that will cost 1000 now.
I am working on a application that involves remote control. The keyboard and mouse state gets updated about 100 times a second, saved on arrays, sent on the internet, and reproduced. Perfect reproducing timing is required. Since now I only coded the keyboard part and it was actually easier to program than windows messaging. All I had to do is call GetAsyncKeystate every 9 milliseconds on the host, and then, on the client, use SendInput every 9 milliseconds to get perfect timing. The other side of the medal is, I will have to manually check if the host window is highlighted, and if is not, avoid calling GetAsyncKeyState. But now that i'm about to code the mouse part, I have a doubt about what method to use, since perfect timing for mouse will be difficult to achieve even without window messaging. That's why I am asking to programmers that are more experienced than me:
In this case, is it better to use a combination of GetAsyncKeyState and GetCursorPos or is it better to use Windows Messaging? What are the positives and negatives of both? Thanks in advance.
You'll want to use a Windows hook. See SetWindowsHookEx and related documentation. This can be used for keyboard events as well.
On recent Windows versions there is also a newer, asynchronous input capture technology available whose name escapes me at the moment. Google for that as well.
EDIT:
I remember now: The other technology is known as event hooking. See the SetWinEventHook function.
GetAsyncKeyState and GetCursorPos is your best choice. The simpler the code, the faster your program will be able to be. Considering that sending windows messages through functions like SendMessage() gives you the option to fiddle with a lot of different aspects of different programs, this usually means that there are more processes happening inside the SendMessage() function and that speed is taken away in order to provide practicality for other applications.
I would also like to point out that you will never be able to get perfect timing since you are in fact collecting data from the source computer, passing it to an array and sending it online.
Summary:
Pros of using GetAsyncKeyState and GetCursorPos:
You won't find any functions retrieving data faster than these functions given that they are functions that only look to do small basic tasks. SendMessage type functions will be slightly slower since they have more coding inside them, allowing them to work with more than just mouse and keyboard functionality.
Cons... I don't really see any.
I have coded up a low level keyboard hook using SetWindowsHookEX() on Windows CE 4.2 and it seems to work just fine. I am able to see key events using the keyboard and a barcode scanner in notepad and other applications as desired, but I do not see the barcode scanner events in the one application that I want to collect the keys in. I still see events from the keyboard, however, so I know that the keyboard hook is still working and in the hook chain. I have even tried inserting my hook in the chain every millisecond just to see if it would make a difference, but no dice. If I flip back to notepad, it's back to working the way I want it.
I'm not sure what the other application is doing to gain control of the scanner when that application is active that prevents it from acting like a keyboard any more. Any thoughts on this would be greatly appreciated. I've done a bunch of searches without any success. I looked into trying to use RAWINPUT, but it doesn't seem to be supported in Windows CE 4.2 from what I can tell as I don't see the user32.dll in the SDK.
There are two ways to get barcode data on most WEC devices.
The keyboard wedge (where data comes in as as keyboard events)
An OEM specific barcode reader API
If this other app your looking at uses option #2 then there is no keyboard data to retrieve, so it makes sense you wouldn't see any. That said, you might read this article to see if it offers any tips for your keyboard hook.
Functions exported by user32.dll in big Windows are generally found in coredll.dll in WEC/WEH.
-PaulH