4

I am trying to build a C# background app that would hook keyboard keystrokes (e.g. CAPS + (A/B/C/....)) to act as a Copy to many different clipboard.

First of all, I looked for a Windows Method that would act like a CTRL+V does : Directly paste a full string. I Also tried the SendInputs to "paste", wrong idea it took too long to execute. As I did not find any goods, I decided to use the Windows Clipboard.

Scenario is (when I do CAPS+A)

  • Cache the content of Clipboard to retrieve it later
  • Simulate a CTRL+C
  • Get content of Clipboard and set it for a variable corresponding to 'A' key
  • Set the Clipboard to the default cached value.

This works well when I am on Notepad. But I get the exception CLIPBRD_E_CANT_OPEN at step 3 when the CTRL+C is executed on another application (for exactly 5 seconds, the Clipboard is not accessible by my application)

My questions: - Is there a way to send Windows a signal for it to "Paste" some given text, acting like a CTRL+V without using the Windows Clipboard ? - Is there a way to force the Clipboard to get back to my application within 5 seconds ? - Am i missing a smarter scenario ?

Thanks!

kokolol
  • 123
  • 10
  • Simulating keystrokes is *totally* the wrong way of going about this. This is a seriously large undertaking, though, and it doesn't sound to me like you're up to the task yet. You might want to look at an existing open-source (or even commercial) package that does this, instead of writing your own in C#. I've never tried it myself, but [Ditto](http://sourceforge.net/projects/ditto-cp/) looks like a clipboard manager that you can check out. – Cody Gray - on strike Jul 27 '14 at 12:04

1 Answers1

0

Take a look at this to intercept Keys before of all:

[DllImport("user32.dll")]
public static extern int GetAsyncKeyState(long vKey);

VK_CONTROL = 0x11
VK_SHIFT = 0x10
C Key = 0x43

The function return an integer value>0 if a key is pressed.

Microlang
  • 534
  • 4
  • 7