1

How would you go about sending key commands or keypresses of particular keys in C#, specifically numbers.

For instance I would like to simulate typing "512" programatically.

Possibly Related: C# SendKeys.Send

Community
  • 1
  • 1
John black
  • 527
  • 2
  • 6
  • 9
  • 1
    I'm a little lost, how would you keypress an integer without simulation? – Quintin Robinson Jan 12 '11 at 17:12
  • 3
    Please explain what "keypressing" an integer variable means. – Oded Jan 12 '11 at 17:12
  • Do you already know how to simulate key-pressing chars and what to know how to do it with integers? Or is simulating key-pressing the real question here? – Austin Salonen Jan 12 '11 at 17:13
  • Here's an example. The integer is 512, I know I could simulate keypressing it by entering the key 5, then 1, and finally 2. But as I say - it's not constant so I don't know how to do it. – John black Jan 12 '11 at 17:14
  • @John black: Is this what you mean: you have a key code, and you want to trigger whatever mechanism exists in a UI you're interacting with corresponding to the keypress for that code? – Dan Tao Jan 12 '11 at 17:15
  • @John black - How are you simulating? What with? What do you mean by "simulate keypressing"? – Oded Jan 12 '11 at 17:15
  • In that case you need to raise an event on a Visual Object, let's say a text box – Carlos Valenzuela Jan 12 '11 at 17:16
  • Please reopen the question so I could accept m0sa's answer. It's a real question, I just didn't describe it well. – John black Jan 12 '11 at 17:18
  • 3
    I kind of think the SO users were too quick to close this one. You gave the poor guy like 5 minutes to clarify his question. – Dan Tao Jan 12 '11 at 17:18

3 Answers3

7

If you would use inputsimulator you could just do:

   var number = 2011;
   InputSimulator.SimulateTextEntry(number.ToString());
m0sa
  • 10,712
  • 4
  • 44
  • 91
1

An integer variable doesn't have a UI, so can't have a keypress.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

Events are for visual objects, not for variables

Carlos Valenzuela
  • 816
  • 1
  • 7
  • 19