I am currently trying to get real-time keyboard input (both press, hold, and release) in a C# console application. I've found a way that works using only Console.ReadKey(). Problem is that windows sets a delay before a key is repeated. I have found various other questions asking how to change this in code, but all the answers simply tell you to use the built in press, release, and hold events in a windows forms application. I can't use those in console.
As a note, i do not know much about API coding or DLL's.
See this previous post by me for further motivation if you need it to answer: C# Console application: Console.Readkey() has odd initial skipping behaviour on high framerates
Related
I want to make a GUI Windows application that can run console applications. When this happens, the console window should not be shown. Instead its content should be shown in a visual component (memo/richedit). This component should show exactly the same content which would appear in the console window, even the color of the text and its background should be displayed. So this visual component should work exactly as a console window. I know that the standard output can be captured but many console applications do not use it. Is it possible to capture the output of a console application this way? Are there Windows API calls that can handle this?
I use Delphi XE2 but C# code would also be helpful.
You have to run the console mode program with stdout redirection to a pipe that your Delphi program will create. Your Delphi program can read the pipe to get the console mode program output and do whatever it needs to. By the way, this works not only with Delphi but also with any language able to create pipe and run program with I/O redirection.
If you need Delphi code to do that, have a look at this reference.
There is a ready-to-run component on GitHub: DosCommand
The Demo shows two ways how to do what you describe.
I am not sure if it works for older versions like XE2, but at least you can give it a try.
Traditionally you would call CreateProcess with stdin/stdout set to pipes you created. This should work for most programs but not for anything that uses a ncurses style "GUI" and you also lose the color information. An example can be found on MSDN.
Windows 10 (1809?) added support for pseudoconsoles. This is used by the new Terminal application and is your best bet for full console compatibility.
The last alternative is to inject into the child process and hook WriteFile, ReadFile and all the console functions but this is ugly and error-prone.
I am working on a program that starts several other c# WPF applications and checks wether there are errors (using .NET Automation Services / UITesting).
One of the requirements of it is to take a screenshot of the main window and to put it into a word document. I alread got it working quite fine when it´s one application at a time (using code from this site: http://www.developerfusion.com/code/4630/capture-a-screen-shot/) , but as soon as i am using parallelism (say, checking 5 applications in a parallel manner), i am running into the problem that the screenshots of the windows may be overlapped by other windows that just popped up or that are always brought to the front (e.g. splash screens). Bringing the window to the front does not really help.
There was an older similar thread not directly regarding to WPF applications, and sadly, without a clear solution: Taking screenshot of a partially hidden window in a programmatic way
Is there a way to get a "clean" screenshot, may be with the use of the windows AutomationElement instance?
This question is asked alot, but I couldnt find working method / way to do it - except for a third party application.
I am pretty sure, or atleast I am being very hopeful that solution for this problem does exist.
As the title says, I want to disable window 8 gestures just like every third app is doing (SkipMetroSuite, ClassicShellMenu or w/e).
I need it to be built in in my app because I cant install anything on the compter my app is dedicated to but my app itself...
Is there a way to do it in C#?
EDIT:
I personally asked the developer of Classic Shell Menu how his programs works, here is the answer:
The principle is to inject a message hook in the thread of window with
class “ApplicationManager_DesktopShellWindow”, then listen for mouse
messages sent to windows with class “EdgeUiInputWndClass”, and hide
those windows. When my program exists it reshows all windows that it
has hidden.
He also mentioned I can find the solution here:
Classic Shell src
But there's one problem, the solution is in c++ and I have no Idea how to port it to c# so I would appreciate your help.
The solution is in ClassicStartMenuDLL.cpp which is in ClassicStartMenuDLL Solution.
The first step to what you want to do is to disable Metro mode (the start screen tiles).
You can achieve this via a registry edit, which you can do programmatically.
The entry of interest is the following:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RPEnabled
You need to set this to 0
Next, you want to disable the 'hot corners'. This is also a registry edit which can be done programmatically.
The entry of interest is the following:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ImmersiveShell
Create a new key called EdgeUI, and under thay key create the following DWORD entries:
DisableTLcorner
DisableTRcorner (Windows 8.1+)
DisableCharmsHint
Set both values to 1
Since these are both HKCU settings (i.e. current user), then a simple log-off is all that is required for them to take effect.
Alternatively you can kill the explorer process, though it is not recommended.
If it is not working for you, try to test it with a ready-made registry file first, since you might be doing something wrong -> Disable Charms & Switcher
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to have an application without any viewable form(for run in system tray only).
now, when user pressed a hot key(for example "F11") , copy selected texts from an application into clipboard , then I want to print texts in defined format .
now I don't know how can I do that.
please help me...
thanks a lot
You need to use Hooking that contains 3 main part:
A system hook allows you to insert a callback function which
intercepts certain Windows messages (e.g., mouse related messages).
A local system hook is a system hook that is called only when the
specified messages are processed by a single thread.
A global system hook is a system hook that is called when the specified messages are
processed by any application on the entire system.
In Addition to your requirement, you need to use Global system hook. You can use this helpful link.
UPDATE:
I think It's the simple side of story to detect keyboard pressed key, or put an formless app in system tray (Trough This LINK), Also you can easily set a text to clipboard using System.Windows.Forms.Clipboard.SetText("Hello, clipboard");But , What Text? That's the point of interest. If you wanna get the selected text from any open app that contains select-able text, You need to go in a different way. I've searched a little about it and got this respectable LINK.
UPDATE AGAIN:
As you mentioned in comments, the link's guide doesn't work proper for your demand. I tested it just a few minutes ago and wrote a sample app using that. I've got the selected control text from active windows as result, that means it will nit help as well.
A little searched again and the result is as below:
It is not possible in general to be able to get the value of "any" selected text, because of the fact that programs can re-implement their own version of the Win32 controls any way they see fit, and your program cannot possibly expect to work with all of them.
You can use Microsoft UI Automation that is the new accessibility framework for Microsoft Windows, available on all operating systems. UI Automation provides programmatic access to most user interface (UI) elements on the desktop, enabling assistive technology products such as screen readers to provide information about the UI to end users and to manipulate the UI by means other than standard input. UI Automation also allows automated test scripts to interact with the UI.
Note: As i saw in the samples and questions around it, this solution is not very cool and in addition to others experiment, it won't work for all of apps(Such as Firefox, etc).
Any Helpful quote will add to the answer. It was All I've got for you.
Be Lucky
This question already has answers here:
Keep window on top and steal focus in WinForms
(5 answers)
Closed 9 years ago.
I'm developing a simple program that reads a card or a barcode and logs that on a database. Before, I developed the same application in Visual Basic and it was working great, but due to a lot of changes on our servers, we decided to develop this app in C#.
I can get my application to start with Windows putting its shortcut on 'startup' of the start menu but the problem is that its not getting focus so that the cards and barcodes can be read and that way my program is simply useless. The machines we use are running Windows XP and Windows 7.
How is the best way to start my application on Windows Startup and keep the focus in it?
This is, in general, a pretty bad design. I just finished a project involving barcode readers and set them up to act as serial ports, instead of keyboards. You should check whether this is an option with your hardware, as the end result will be much more reliable.
That being said, you can create a timer in your form that executes this.Focus() and this.BringToFront() to steal focus. Be aware that this will, by default, only cause the task bar to flash. You'll need to use TweakUI to enable focus stealing.
Another option is discussed here on SO. Very similar question, actually. Basically, you hook the keyboard input at a low level.
Please try and find another way, monitor system events or use a polling mechanism.
Stealing focus should be avoided, read this to understand why
If I had a dollar for every time I typed a password, cleartext in the wrong application because it stole focus...
On Form Activated Event call This.SentToBack()