Andrey
Andrey

Reputation: 13

C# InputSimulator: choosing key from combobox

I have array filled with key names from InputSimulator.

readonly string[] keys = new string[119] 
    {   
        "",
        "TAB",
        "RETURN",
        "SHIFT",
        "CONTROL", 
        ...
    }

After that I fill comboboxes with this strings. There are 3 comboboxes.

So, I would like to use such a function:

sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);

Is it possible to fill arguments of this function with key names which were selected in comboboxes?

It was obivious for me, how to do it with SendKeys function, cause it was using string as an argument, but now I need to do it with InputSimulator.

Upvotes: 1

Views: 202

Answers (1)

StupidUser3186
StupidUser3186

Reputation: 90

You could have the array contain all the keys in the order they are in on the VirtualKeyCode Enumeration. Then you just cast it into a VirtualKeyCode as soon as you use ModifiedKeyStroke.

like so

sim.Keyboard.ModifiedKeyStroke((VirtualKeyCode)combobox1.SelectedIndex, (VirtualKeyCode)combobox2.SelectedIndex);

EDIT:

Beter yet, you could use Enum.Parse(typeof(VirtualKeyCode), comboboxvalue) to get the desired enum based on the combobox string value and use it in the function.

Like so:

sim.Keyboard.ModifiedKeyStroke((VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), combobox1value), (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), combobox2value);

Upvotes: 1

Related Questions