C# Custom paste like feature - c#

I am trying to create a way or inserting text anywhere on the system in Windows, much like the clipboard works. For example, pressing ctrl+shift+1 would 'paste' text set in my application into where the user is currently pointing the cursor.
For example, if my application sets it to be 'local.network' and the user presses ctrl+shift+1 in their browser address bar, it would paste in 'local.network'. I then want to have different values set, depending on what number the user presses. Is this possible or can I not create a system wide function like this?

What you're looking for is how to register a hotkey.
Register more than one hotkey with RegisterHotKey
Set global hotkeys using C#
in response to your followup comment, sorry, I though the question was more about the capturing the key press event. If you need to paste text to a window that you don't own, then this question would be a near duplicate. That question uses WM_SETTEXT but you can easily use WM_PASTE instead.

Related

Get new Messagebox style - WPF

I am currently working on a Windows Presentation Foundation app and I need to make use of Message boxes. I want to get few information from user inside Message Box popup.
But they appear always like this:
But I think the actual look of it should be like that:
Does anybody know, why this is, and how to solve it? I tried all everything listed
here
, but nothing worked.
I agree with Keithernet, build your own. Its more of an Input Dialog box. You may want to plan it to create a window, create it with ex: 4 parameters which you could override so you can apply them in the form including
The title,
The prompt you want the user to fill in
optional default button 1 text
optional default button 2 text.
have the input value stored into a public property in the window for the text to be bound to during entry.
If the user clicks the cancel button (or similar), clear the text entry and close the window. If ok button, just close the window.
Then, when you call it with a YourWindow.ShowDialog(), upon return, you can look at the public property for that input text value.
You could even do with a property / flag if the user cancelled directly or not. I have done similar in a couple of my WPF apps.
MessageBox is very limited. Based on your screenshot, you should just create your own child Window with your own XAML so you can get the user input.
You can find sample service implementations/NuGets for this on GitHub. Here is one I've created sometime ago: https://github.com/Dirkster99/MsgBox
Just create your own is an oversimplifying statement in my opinion because this is usually a dialog that you want to show in different parts of the application. Therefore, you have to settle for a software design pattern (I chose a service implementation as suggested here).
Likewise, there are other design decisions that should be taken. I have for instance made sure that the API has a compatible subset of Show API calls with the standard .Net MessageBox to make its application as flexible as possible. I also settled for light and dark themes hoping this will make its application easy in any other theme...

Spying / pressing buttons with C#

In BluePrism it is possible to spy buttons, fields etc. of any windows application and then click those buttons automatically. For example, if you look at the screenshot you can see the attributes of the calculator's button "1" as spied in the Win32-mode (there are also HTML-, Accessibility-, Region- and UI Automation-modes) by which BluePrism will be able to identify and click the according button. Furthermore, BluePrim is compatible with C# and I wonder whether (and how) I could also get those attributes via C# instead or at least use the spied attributes as can be seen on the screenshot to press the same button with C# instead?
EDIT:
It would be highly appreciated if someone could provide the C# code for pressing the calculator's button "1" to get me started (I'm a C# newbie :-) Thanks!
You do not need C# for that, you can just use a Reader stage and action Get AA Attribute or Get Window Attribute.
EDIT:
But if you really want to do it using .NET only, have a look at UI Automation or Active Accessibility Automation (older one)
This seems like a nice example.
You will also find a tool called Inspect.exe very handy to spy elements without using BP. This
You can use the Application Model that you just spied, put it in a navigate stage in your object, then select Click Mouse Centre as the action. This will result in the button you have spied being clicked. Generally, to use Sendkeys is with C# syntax, i.e. use the root element (root element and top of list in Application Modeller tree) and select Global SendKeys as the action inside a navigate stage. In the Text input field you can enter your C# sendkey code, like for example for Ctrl + Alt + Delete use: "^%{DELETE}". I think this is what you may be looking for? Otherwise, if I understand correctly, you might be looking to use a C# code-stage inside BP to pass sendkeys to an application attached to a BP process, which would possibly involve referencing each and every attribute of the host application in C# and then using (for example) the C# Enum properties of each keyboard key, etc... this would be a massively redundant exercise since BP already provides the functionality inside the navigate stage as explained above.

How to capture keystrokes before the foreground window gets it?

I'm doing an application like Google Transliteration (Google input tools) tool in C#. It displays the suggestion window on the top of whatever window we are typing (finds caret location & display just window below it). But the focus (foreground process) is still on the application in which we type (for eg. Ms Word, Notepad etc.).
I want to implement these features of Google Transliteration:
It captures the keystrokes before another process gets it.
While renaming a folder or file, we can select words from the suggestions
window show up by using up & down arrow keys and press enter key. But the
rename text field will be still active. The keystrokes will be
captured before it reaches rename text field.
I want to implement a universal text suggestion list (window) like that of Google Transliteration.
How to capture keystrokes before another process gets it (block foreground process from getting it)? (Main Question)
How to capture keystrokes (up & down arrow keys and enter key) and select an option from the words list without focusing on the 'words list' window?
(Caret should remain active and blinking on the foreground process text field. eg. Folder rename text field)
Someone please help me to solve this problem.
I already found this one, but it not helped me to solve my problem.
Capturing keystrokes without focus
You mix two different problems. The first problem - to catch keyboard input - nothing to do with the second - to make an unfocusable window.
The solution to the first problem is very simple - as stated in your link, there is no other way to do it other than Low-Level windows hooks.
The second problem is more difficult, the solution may require a little experimentation, creativity and knowledge of WinAPI. Examples are here, here and here.

How to write text to an external application

I'm developing an application to help the user write common text faster.
What I have in mind is a Windows app where the user can configure his key combinations, so that when he's, for instance, writing an email on Outlook or Gmail, he just has to press those keys and the text he configured before will be pasted into whatever app he's using.
So, instead of a user having to write "Dear sir, your order has been received succesfully" every time he receives an order and wants to send a confirmation email, he could just press something like "Crtl + O + R", and the corresponding text will be written for him.
I think that in order to achieve that my app has to do two things:
Intercept the key combination pressed buy the user when he's focused on a different app.
"Paste" the corresponding text to that app.
I have no real clue on how to achieve this, because what my app will be doing is something like "pasting" text on another app (otlook, word, notepad or whatever thing a user can type into), replacing the short text the user wrote with the long text he defined.
Any suggestions? I've looked into hot keys, but I'm not sure they're the way to go, and I also have no idea on how to "paste" the new text.
Thanks.
Have you considered simply adding text to the clipboard? Show the text next to a button that says "Copy to clipboard", and the user can just grab it and click Ctrl-V.
Can't think of a Windows app that does it this way, but I know it's possible; heck, Bit.ly can do it from your browser.

How to make a right-click translation dictionary application?

I'm trying to write a dictionay application on C#. There is a scenarios that user selects a text and press a hot-key, I want to pop-up a quick windows that display the search result of the selected word (just like Lingoes does)
How would I do it in C#?
Thanks in advance
Start with Google this:
hooks, global hotkeys (for monitoring global keyboard and mouse events)
WinAPI (to do such tricks as grab any selected text)
I've written program you're talking about. You can check the code here - IDictionary.
Regards

Categories

Resources