How to delete delay on SendKeys.SendWait? - c#

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.

Related

How to programmatically add/modify/delete available display settings (width, height, refresh rate)?

I want to code (in C#) a tool to add/modify/delete some of the available Windows display configurations (width, height and refresh rate).
Can this be done programmatically? I've spent many hours trying to find something about this online but had no luck.
The reason i want it is because of some older full screen games that keep setting the refresh rate back to 60hz from whatever it were when the game started (120hz in my case). I can solve that problem using Alt-Tab twice but I rather want to just limit the available display configurations (or change the refresh rate for some of them) instead.
Before considering all this I've tried to solve my problem with these attempts:
Intercepting the keyboard (using this class Global keyboard capture in C# application) and then attempt a force display change when a hotkey it pressed. It works fine for just about all normal apps. But when a full screen game is running the keydown event doesn't fire. Either it is not possible when a full screen game has focus or I don't just know how to do it properly (very likely as I am a newbie in that regards).
Tried using a timer to periodically check for a certain resolution and if 60hz is detected then try to set it to 120hz. The timer does fire and the code tries to change the monitor (which flickers briefly) - but the refresh rate doesn't change.
Another idea I had was to use Mhook or Detours to intercept the 'change display setting'-call. But I don't know if that'll work. And I also have no experience with C++. So I really don't want to go that way if I can avoid it.
Can this be programmatically? I've spent many hours trying to find
something about this online but had no luck.
This settings are not part of the standard .Net Framework but there is interface to manipulate these settings for windows problematically using win32 APIs. you can look here on how to call windows APIs using .Net Framework. then you can call a windows API to change the resolution for instance.

How to detect whether user is on the desktop C# winforms

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/

how to make windows startup project with many methods running at the same time in the background

I have explained my project below and asked some questions with "My Question-" tag.
I have working on a project. At the time of windows logon page if I enter a wrong password my cam should take the picture, If I open regedit my system should take a screen shot and save these images in C:\Windows\system32\new folder (I tried a lot making this work with the help of manifest files but failed everytime) and emails it whenever finds an internet connection
I have a form based app because I didn't find any other way to capture image from webcam directly but taking input from pictureBox1.Image.
My cam, screenshot,email (didn't find a way to autocheck if has internet connection available or not) and 3 events checker for "firewall enable/disable, windows logon failure , regedit event called" are done and they are working good.
What I need to do is to assemble these codes to work as an app and running in the background continuously from the time of windows startup to shutdown
To validate positive events I need to make a desktop based db ("My Question"- still figuring out either to choose sql or localdatabase in c#. Please also tell me a suitable solution.I have to delete all the entries from the db once a day is over). The db would contain the following columns (event id, event name, event timestamp).
I want my app to check if this very event exists in the db then it should ignore the event generated on windows event log else it should make a new row with the db columns and it should do the following actions based on the event like taking webcam pic or screenshot.
"My Question"- I want my app to be live at the time of windows logon page. A lot of programs start later when you are authenticated but I need my program to be live at the time of logon page. Do I have to make 1 or many services? or multi-threaded? because in the typical form based app you can only call one function at a time and wait for it to return something or perform some task/action and then you call the second third whatever.
"My Question"- Do I need to use the backgroundworker in c#
Please help!
You have a lot of things going on here for one question.
You can put all your code in a background service that gets started at boot time. There is a walkthrough here to show you how to do that (along with a million other sites).
Addressing some of the other issues you listed:
Google is your friend...
Webcam - Found a quick reference here and here
File Modification - Another SO thread here
SQL vs. Other Database - Not sure you need anything elaborate here, probably something you can put together pretty quickly. Another SO thread addressing that here
Good Luck!

How can a screensaver continue to draw over the desktop in Windows 8?

I’m developing a screen saver in C# .NET4.0 on VS2010 which needs to do a fair bit of processing before it actually shows screens (fairly complex database access). This is fine because the user is unaware that this processing is going on and then the full screen forms kick in when everything is ready. That is, unless we are running on Windows 8.
Searching on the Microsoft Community (http://answers.microsoft.com/en-us/windows/forum/windows_8-desktop/bubbles-screensaver-has-black-background/e0807324-5ca6-4abe-b6ba-716848b41ff5?page=4) reveals that a design change was made in Windows 8 that prevents screensavers from drawing over an image of the desktop. Any screensaver that previously drew over the desktop will instead draw over a plain background using your chosen “metro” background colour. Experimenting reveals that this background kicks in immediately the .scr file launches i.e. before any forms can be displayed. Hence tricks like displaying forms minimised or with 0% opacity don’t work because this simply reveals the plain background underneath.
The best I’ve been able to come up with is to display full screen plain black forms as first action when my code starts i.e. before any database processing or other screen construction takes place. Why try to replace a plain screen with another plain screen? Well, because the default Windows background colour seems to be blue. That’s blue as in BSOD blue which looks kind of alarming when it kicks in. So the best I can do for a Windows 8 user experience is a quick flicker of blue followed by 3-4 seconds of plain black before screens are populated with something meaningful.
This new behaviour from Microsoft is apparently “by design”. The fact that it doesn’t manifest itself in Preview mode is apparently an error which one supposes MS will tidy up later.
So my question is does anyone know any way around this so that I can continue to have the desktop showing until screensaver forms are ready to kick in?
I struggled quite a lot with a similar problem regarding this awkward design decision in win8.
I the end had to compromise but my search continues for a a bullet proof solution, when I have time.
Now what I ended up with is running a batch file after the monitoring system starts and have thread detect idle time and run that batch again.
#start /wait Bubbles.scr /s & rundll32 user32.dll,LockWorkStation
What this does is:
starts screensaver preview in fullscreen (this works in win8) and waits
on user action lock screen is show and user prompted for password
As I said it's a compromise until a find something better. Hope it helps
Updated to win10; try to use that cool scr and found same issue;
Try to trick ms restriction and found only one very long solution:
enable logging of screensaver invoked events;
here instruction via gpedit: https://superuser.com/questions/538146/run-a-batch-cmd-upon-screensaver
now you will able to start other comand or app when screensaver starting;
goto C:\Windows\System32
copy Bubbles.scr and rename to Bubbles.exe
then config task to run C:\Windows\System32\Bubbles.exe with argument /s (administration->taskcheduler)
use some windows screensaver and config to use 1 min or more; (or use 'runsarver' with empty options from upper link or create your own empty.exe and rename to .scr and install with right menu, etc)
Found cool app to customize hidden screensaver features: http://winaero.com/download.php?view.8
(work with small bugs but work as needed under win10)
All work fine one cons checkbox to lock PC must be unchecked;
If needed create own app to run Bubbles and on exit lock PC or bat file as above, etc;
hope people will have fun with my solution :)

Application running in background and still be active?

I have a Windows Form Application that reads a barcode from a Web Cam.
Everything is running smooth but I still need to implement a function to the application to keep listening my keyboard inputs and be able to read the barcodes and put the reading in the clipboard.
In other words, do the stuff that my program has to do but in the background.
I searched a lot in the internet but I couldn't find any good answer to my problem.
Can you guys help me?
Thank you a lot!
There's more than one way to perform this.
So the problem is that your application doesn't have focus, and so doesn't get keyboard/mouse input passed to it. To work around that you can use Keyboard hooks.
Alternatively, you can perform polling. That is, run your 'scan' periodically - quickly enough that the user doesn't need to enter keyboard input, they just put something in front of the web cam for a second, and it scans.
You need to use a background worker to read the barcode so the main thread is not locked up. Below is a microsoft example:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

Categories

Resources