I know there's been some questions around this topic, but the ones I'd like to ask are somewhat more specific:
Does there exist any other method of simulating mouse movement than throwing WinAPI calls all over the place? If yes, is it any good compared to wrapping these calls in my own class?
For the record: by "mouse movement", i mean all the click and repositioning, preferably, but not absolutely necessary, with visible animation of cursor moving between positions.
Back in DOS programming I had dynamically grabbed the interrupt which you can't do the same way under protected mode but I am pretty sure that DirectInput also has some functions somewhere that would be different than the Win32 way
There are alternative libraries for input handling which I would think the SDL has and possibly GLFW but it may be a stretch to go adding those to a project for mouse handling.
Correction: SDL uses DirectInput on windows.
I don't know how much more agreeable you find .NET than win32 but there is one other way too. I was sure I had a bookmark somewhere to a library that would fit perfectly =/ where is it...
.NET way, not bad if you're already using .NET especially:
MSDN Reference Page
As far as clicking goes for that solution, just send a message to your main loop or where you are already detecting clicks instead of setting mouse click. Though I'm sure there are other libraries with the function out there.
UPDATE: Check out http://wiki.osdev.org/Mouse_Input for some information on more direct usage and driver writing. This and, as it turns out, use of INT 33h is also possible under windows (and other more dev-friendly OSes) with some effort!
If you can live with only simulating clicking on the various controls, try manually triggering the controls' Click event, or, for buttons you can use Control.PerformClick().
Related
I have a very simple method that writes a file locally but I only want to fire it if the user looks like they are going to drop outside of the app because firing it every time they start dragging would result in lots of unnecessary files being written.
So my question is: if a user drags something within the app outside of the app, is it possible to detect when they drag over a valid drop target (e.g. the desktop or windows explorer)?
EDIT: At a more general level, my question is: how can I respond to mouse/drag events that occur outside of my app?
Not entirely sure what it is you're exactly trying to achieve, but this may help:
WPF: Drag and drop virtual files into Windows explorer
For the most part the drag / drop events should fire regardless of where you're dropping to (I think), but you can certainly be notified when a drop has been performed.
As #Quarzy stated, unless you're in communication with the other app, there may be no direct way of testing for data that the underlying windows drag / drop system doesn't expose.
More specifically that question points to this article: http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx
I post this purely because I wonder if maybe it may lead to other things, apart from that you might be able to get the Hwnd of the control under the cursor - possibly http://social.msdn.microsoft.com/Forums/windows/en-US/3df9fc84-4020-4ae1-8b4f-942bce65568f/find-the-object-under-the-mouse?forum=winforms as a starting point.
There may then be a way to query whether that particular control is a valid drop target through interop as well.
Good luck!
This might be a possible answer for your question: Register a global hook to detect whether mouse dragging files/text
How ever the following suggestion might help (Require you to create c++ external lib):
Capture other possible processes window message (Global hook WH_GETMESSAGE) (See this link How to Create a global WH_GETMESSAGE HOOK without DLL)
Listen for WM_DROPFILES
see the following link: http://www.experts-exchange.com/Programming/Languages/CPP/Q_10203575.html
You have also an helping answer here How can I capture mouse events that occur outside of a (WPF) window?
But I do not see any way to detect if the target is valid, as long as you have no communication with the potential targets.
I have got a problem when I try to control another Windows application using my own C# application.
The requirement is like this. The "another application" is a business software which our company have bought. We want to develop an application to fill text boxes and simulate mouse clicking. All text input is from a certain XML file.
I have tried to approach such function with SendMessage and SendWait function call. Problem is in some cases or at some end user's laptop, the text filling is not correct. Meanwhile, the mouse clicking will be fail in some other cases.
My imagination of the reason cause is synchronisation problems with call SendMessage. But I have no idea how to fix it. Is there any suggestion or solutions?
Looking forward your reply.
SendMessage and SendWait will always have those sorts of issues (especially app-to-app), e.g. the user clicks someone on the screen at exactly the right/wrong time. Really the only way I know to reliably do this is by hooking onto the mouse/keyboard and take total control... its hard and painful.
Note: there are plenty of professional macro'ing software packages on the market (faking keyboard input, mouse movement, clicks etc). Some are very sophisticated with their own programming language and will possibly do what you want. Google "windows macroing software" and you will find heaps - I recommend you do you research, trial several packages til you find one you want and then purchase it.
How can I create a window which is fully apparent to the user but is not visible in screenshots. I know that this is possible since Neo SafeKeys (an onscreen keyboard to defeat keyloggers) does not appear in the screenshots taken by keylogging software I installed.
To give you an idea, the window is fully visible to the user, however when a screenshot is taken, the Neo SafeKeys window does not appear at all (as if it does not even exist).
Neo SafeKeys states that it uses an invisible protection layer above the window to protect against screenshots. I have searched all over the internet to see how can I reproduce this, to no avail. Does anybody know how this can be performed (windows which is visible to user but invisible in screenshots)?
What you can do is you can prevent the PrtScn key from doing anything when pressed. Take a look at this article while shows you how to do this.
What this article is doing is clearing out the clipboard. What you can do instead is capture the screen image and digitally remove your application, then put the revised image on the clipboard, thus giving the "Effect" of making your window transparent.
Also, you might want to look at this SO question which gives an alternative way to make your window just appear "blue", though its not easy to do.
Does anybody know how this can be performed (windows which is visible to user but invisible in screenshots)?
Use DirectX to render directly to the device.
In your C# application you can set up a global hook to monitor keyboard events. Then your application becomes the global handler for print screens. Now if another application managed screen prints natively, can't stop that, but anything running through windows, you can get at.
The WM_KEYBOARD_LL hook is one of the few global hooks that can be used in managed code because it doesn't require a DLL to be injected into every target.
For some code you can visit here:
Adam's Blog
Keep in mind that these are global hooks so you want to make sure nothing else (other applications) are effected. I've used these in the past as we hosted showing a power point in an application we worked on. Basically we didn't want the user to invoke any powerpoint menus or keyboard short cuts so we used a global hook. We always checked to see whether the users was in a certain area (screen) and in our application, otherwise we would effect other applications functionality (including our own!)
Microsoft Information:
Hooks Overview
There's this.....
visual cryptography
live example here
But this could be easily coded against by taking multiple screenshots and laying them overeachother and such...
If you are using Windows, and you can avoid that screenlogging happens, you can implement a nice solution like a virtual desktop to embed your process into it. When a process is running inside a virtual desktop it is possible to bypass an screenlogger tool that runs over win32 Api.
Check out this article so you can sneak a peek how to implement a nice solution to scape from screen and keyboard monitoring.
http://www.codeproject.com/Articles/7392/Lock-Windows-Desktop?fid=62485&select=3139662&fr=101#xx0xx
How can I disable Print Screen functionality while my WPF application is running?
The use-case is that my client wants to avoid unnecessary replication of valuable patient-centric data from the outside world and they provide the physical security to keep people from taking data through non-digital means.
Okay, it is possible, and could indeed be useful if your application is deployed in an environment where a camera is not available to the user.
First of all, I used the RegisterHotKey and UnregisterHotKey API calls, documented here http://pinvoke.net/default.aspx/user32.RegisterHotKey as described in this rather old article here http://msdn.microsoft.com/en-us/magazine/cc163713.aspx.
I registered the IDHOT_SNAPDESKTOP hotkey in the Window_Load event and unregistered it in the Window_Closed. Trying to do this in the constructor gave me problems getting a consistent handle with the WindowInteropHelper(this) method.
If you'd like to do more than just ignore the keys you can set up a windows message handler, making a kind of WndProc using,
HwndSource source = HwndSource.FromHwnd(<handle>);
source.AddHook(<WndProc>);
making the handle as described above, and the WndProc implementation yourself.
As yet, I don't know how to "not" handle the hot key and get windows to perform its normal behaviour except, of course, by unregistering the hotkeys.
Its not very elegant or "WPF" but it worked for me.
As #ghord comments
The use of EnsureHandle() looks useful for getting a handler in the constructor.
It's not possible to disable printing, and even if it were possible, it would be easily circumvented by a cell phone camera. Many are in the megapixel resolution range, making it quite easy for someone to get the information they want.
If you want to disable the Print Screen Key on your keyboard, Jodrell's answer gives a way of doing that (understanding that it's not going to keep people from printing, and a determined user will find a way around that).
Really, it all comes down to trust. If an employer can't trust their employees not to remove data that is already protected by law in most jurisdictions (HIPAA in the USA), then there's a bigger issue at stake.
Easy:
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
Simply speaking, you cannot. "Print screen" just copies the pixels on the screen to the clipboard, and is not part of your application.
Basically you can hook to the ClipBoard events and then set the image copied to null if someone does it. So they can copy the image but it will be reset:
Have a look at this:
Clipboard event C#
Alternatively in a timer, check the content of the clip board and clear it as soon as it is set to a picture.
No, No way to do that. Even if you capture the Print Screen key in your application user might set focus to some other application and then do the Print screen(having your application on side etc.).
Only way would be to create a dummy application in background which captures all keystrokes using Keyboard Hooks and filters Print Screen, but that will happen for all applications not just yours. And moreover as George said user can use cellphone camera too!
I think Microsoft Rights Management System can help. Give it a try. Following is the link:
Microsoft Rights Management System
The only way I can think of is to use the native Windows API (SetWindowsHookEx) to catch all keystrokes and filter out the PrintScreen key. However this would involve creating a native (i.e. unmanaged) DLL to actually do the keystroke processing.
Hey, I'm really stuck with my project here... I need to know when any open window has been minimized / restored and Handle the event in my own App. Any ideas?
Edit:
Musigenesis is right, i do want to know when OTHER applications are minimized/restored
I think you would need to use the SetWindowsHookEx Win32 API function (along with a few others). Basically, you would iterate through all open windows in the OS and hook into their resizing events.
Obligatory comment: are you sure you need to do this? While I think this is theoretically possible, it sounds like a pretty bad idea, and counter to the way applications in Windows are supposed to behave.
Update: I think "Show Desktop" in Windows works kind of like this, except that it iterates through all the open windows and then uses SendMessage to minimize them if open (total guess on my part).
Update 2: this is a tough one, and I'm very curious to know how this could be done (I'm 100% sure that it is possible). I'll keep an eye on this question, and if no one comes up with an answer in the next day or two, I'll post it again and offer a bounty on it (you could do that, but you need to have some reputation points of your own to offer as a bounty).
Assuming you're using Windows Forms, you can handle the OnSizeChanged event, and test the WindowState