I was making a program that changes the desktop background, but there is no need to do this when the user is not on the desktop.
I was wondering if there was a way to detect if the user was on the desktop.
I was also thinking an alternative could be checking whether the user is on any other processes, but I don't know how to do this either.
(I would happily provide my code if necessary)
I'm sorry for posting such a broad question, I hope there is a way to do this though.
Thanks to anyone who can help!
If you want to check application in idle condition then you have to do below:
Add a timer control to your application.
Subscribe to mouseover and keydown events - when they fire, reset the timer.
When the timer fires (ie mouse hasn't moved and key's haven't been pressed for x amount of time), write your logic.
And If want to check idle condition of desktop then below references will be useful for you:
Detecting that the user is away from the PC with .NET
Detecting that the user is away from the PC with .NET
http://www.codeproject.com/KB/cs/ApplicationIdle.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.idle.aspx
http://ellisweb.net/2008/02/detecting-application-idle-state-in-windows-forms/
Related
I'm writing a program that I want to run when the user is "idle" (I.e. No input from the user - not moving the mouse, or typing anything). I have taken care of detecting if the mouse is moving (through storing the mouse position as a variable and comparing the current position to that variable at a later time), but what I can't figure out is how to detect keyboard input.
I know that if the user is typing in the form itself, I can use event listeners (KeyDown, KeyPressed, etc.), but I want this program to detect keyboard input anywhere on the computer, in any program.
Is there a way to accomplish this? All my research has yielded ways to check inside the form, but not globally.
Note: Not sure if this matters, but I don't care what the user is typing (what keys are being pressed). All I need to know is that there is keyboard activity.
Thanks in advance!
What you're looking for is considered a Global Keyboard Hook.
A sample with explanation and source:
here
Edit: In terms #FᴀʀʜᴀɴAɴᴀᴍ answer, it would be improper to grab using GetLastInputInfo as system calls (SendInput(), keybd_event(), etc) all will trigger it as well, so that doesn't mean the user is technically there.
I'm working on an app (Written in C#) that have a setting to run on KIOSK mode. I've just an challenge here which is disabling Ctrl+Alt+Del combination Event.
There is no right answer in the similar past posts. Please let me know about the right action.
Considering, my code is working with registry keys to disable/enable options, if you know any registry key,it will be more helpful.
CTRL+ALT+DEL is the secure attention sequence of Windows NT (and its derivatives like Win7). It is the one key combination that is guaranteed to get the OS's attention. The whole point of the SAS is that it can't be intercepted or stopped by user programs.
One security issue it addresses is that of a false login screen: consider a screen that looks exactly like the normal Windows login screen. There's no way to tell that it's a fake just by looking at it. But, if you're in the habit of always pressing CTRL+ALT+DEL before logging in (there is an option to always require it for the legitimate screen), pressing the SAS on a false login screen will bring up task manager or the secure attention screen (with the log off, change password, etc options). The real login screen doesn't do that; it just stays there on the screen. As long as the OS itself isn't replaced or compromised, CTRL+ALT+DEL will protect you from false login screens. If a user program could intercept the SAS, it wouldn't be worth anything.
The SAS was baked into the Windows NT design right from the beginning (it was in the first release in 1993), so getting around it won't be easy. I'm sure there are keyboard filter drivers-- or something to intercept that sequence-- that are designed for kiosk use.
It is not possible to capture CTRL+ALT+DEL, it is so by design in all Windows systems. This is a security issue, if the user hits CTRL+ALT+DEL, he or she should be certain that it is the operating system and not some application (possibly a password-catching trojan) that responds to it.
I guess to capture CTRL+ALT+DEL you would need to write a device driver of some sorts.
Edit: Also see This answer. I did not try it, but the question is fairly similar.
Although it is sort of possible, it is not an easy task and not something that can be done in C#. This Article will show you how to disable CTRL+ALT+DEL using group policy editor. To permanently disable the combination though, you will either need to write your own keyboard driver or write your own GINA stub (Graphical Identification and Authentication).
It is possible to pick up the CTRL+ALT+DEL combination, but not to disable it.
I tried to disable it with SetWindowsHookEx and WH_KEYBOARD_LL and you can successfully get notified when CTRL+ALT+DEL is pressed, but you cannot do anything about it.
It is possible to block CTRL+ALT+DEL combination. However, you can't really disable it. As far as I know, there are two possible methods.
Remapping the keyboard layout. There is a registry binary key that allows you to remap keyboard layout:
HKLM\System\CurrentControlSet\Control\Keyboard Layout\Scancode Map
Please check this out: Disabling Windows Hot Keys
This method can be dangerous, but I haven't noticed any side effects this method can cause. The CTRL+ALT+DEL combination is handled by winlogon.exe. If your process has administrative privilege, you can suspend winlogon.exe. Hence, it cannot process the hotkey and nothing will happen if the user presses CTRL+ALT+DEL.
Please check this out: C++ code to disable CTRL+ALT+DEL.
You will need to do some P/Invoke, in user32.dll, there's a method called SystemParametersInfo, check out these resources for more info
http://pinvoke.net/search.aspx?search=SystemParametersInfo&namespace=[All]
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx
I did something similar a long while back, but no longer have the code, though I did find this (it's in vb6), but it shouldn't be too hard to get the idea and translate to .NET
http://www.developerfusion.com/code/1021/how-to-disable-ctrlaltdel/
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.
Hello I want to press a button with my app. So I use SendKeys class
SendKeys.SendWait("{RIGHT}");
Problem is that I need to wait 3-4 seconds after this line code for reaction from system. How can I speed it up or how can I delete this delay ?
// update 1
I've also tried
SendKeys.SendWait("{RIGHT}");
SendKeys.Flush();
BUt id didn't help
// update 2
I want my app that works in background to press a button programaticly in the actual active state of the user. So if he is in excel i want the right arrow to move the active cell, if he is in the game i want to turn right etc. SendWait does the thing I want but with some delay that I don't want.
Second important thing that this is not a virus or worm or anything like that. First of all as you can see I'm too stupid for that and secondly I'm playing with my KInect so this is some kind of interaction beetwen user and computer. Thats why it works in background and thats why I need to send it to the active app of the user
SendKeys is a nice little feature for Windows Form applications. Based on your tag it appears that you're using Windows Presentation Foundation, which will not support SendKeys.Send()
https://stackoverflow.com/a/1646568/340574
Take a look at the link above to use KeyEventArgs. I've read that you could also add a reference to System.Windows.Forms.dll through Visual Studio to use SendKeys, but I have not tried it myself.
I have a program that posts to a database every minute, to show that is running. This is good to make sure that the program is running on a person's computer, but it doesn't tell whether the person is actually actively using their computer (the computer can be locked, or the person might be out of the office, with the program still running and posting to the database).
What is the best way to check if the person is actually actively using the computer?
The first idea that pops into my mind is to create a MessageBox that opens every 5 minutes asking the user to press "OK" if they are present. This would provide the needed functionality, but would annoy the daylights out of anyone using it.
Is there any more behind-the-scenes way to detect whether a person is using their computer? Maybe checking for whether it is locked, or can a WinForm application tell when the mouse and keyboard is being used, even when the WinForm is not the active window?
Any suggestions or help in this matter would be appreciated, thanks!
Addendum: I will assume that if the mouse and keyboard are not being used, a person is not using that particular box (so this would cause a false positive if the user is watching a movie on their computer (this program will be used in an office setting, so the possibility of this happening on a particular day is nearly zero)).
You can set up global hooks for the mouse and keyboard - WH_KEYBOARD_LL and WH_MOUSE_LL - which will allow you to monitor user activity - as long as your user is not, say, watching a film and not touching mouse or keyboard..
The way I'd think about doing it would be to write an application that sits in the background and listens for mouse and keyboard messages using the user32.dll and assumes that the user is no longer using the computer if it doesn't hear any after a certain amount of time. Even then they might be watching a dvd or something though
http://www.ugolog.com/pages/webcam-motion-detection-for-flash-flex-and-csharp
Webcam motion detection + mouse/keyboard hooks = Super Big Brother app.
I think you can do a check using whether screen saver is running or not.
More info : http://bytes.com/topic/c-sharp/answers/261540-detecting-screensaver-state
best way to create some sort of Logging so that it sends usage logs to you. that way you can also analyze what features of the apps have been used actively. Capturing mouse moves and hooks might not make anvivirus on that box happy :)