0

I have a string value in a variable. I want it to be thrown in keypress event.

When user clicks on "Start Writing Button". The text contained in variable gets written to the area whereever cursor has focus.

eg. string str = "Example"

I have a web page with a textbox and a button. When user clicks on Start Reading button Example gets written on to textbox.

Basically the characters being written should be trapped on javascript-onKeyPress event Winform- KeyPress event etc.

EDIT

I want to use some devices that will be throwing data constantly to my variable using window service. I need to write this data to the active window whereever the cursor has focus currently irrespective of window or web.

I copied data to clipboard and pasted on active window but this is problematic since different tabs are considered to same active window and doesn't writes.

Looking for a proper way rather then workaround I have taken.

Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286

1 Answers1

4

Now that you've clarified the question, I suspect you want SendKeys.SendWait.

You'll need to be somewhat careful with it, but it may do what you want.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks for very good link, will start searching in details on it. I saw the line on the article **implementation is still susceptible to timing issues**. Any Idea on how fast would it process since I usually need to send 20-30 characters in less then a second just to immitate as if data was directly written by a device. Moreover I observed its namespace to be System.Windows.Forms. Would it be available in window service ? – Shantanu Gupta Jan 05 '12 at 11:57
  • @ShantanuGupta: You'd need to give the service access to the desktop. Are you sure there isn't a cleaner way of achieving your greater goal? What's the real purpose of this? If it's for automated testing for example, there are plenty of bespoke products you could look at. – Jon Skeet Jan 05 '12 at 12:04
  • I know I am not able to identify the cleaner way and looking for all possible solutions. I have an HID(RFID) device just like barcode scanner. I was expecting that it would mimic keystrokes eg 'http://stackoverflow.com/questions/3655023/how-do-i-read-input-from-a-usb-hid-device'. I need to read data from this device on a web application. I dont know capabilities of browser whether it can access the device or not. But this is my requirement. – Shantanu Gupta Jan 05 '12 at 12:08