Home:ALL Converter>Simulating a modifier key holding in winforms

Simulating a modifier key holding in winforms

Ask Time:2012-08-13T17:45:35         Author:Dumbo

Json Formatter

I have a program that has a TreeView. I made it in such a way if user holds Control Key the data from each Node of taht treeview is being addded continiously to a ListView. Now what I want to do is to programatically select this nodes while simulating the Control key is being pressed.

So the point is, if Control key is not being pressed, the listview which is responsible to show data related to that node, will get cleaned on node select. If control key is being pressed, the data from newly selected node will appended to the list view.

Is there a way to send a key hold message? I mean something like this:

    var nodeCount = tvTestGroups.Nodes.Count;

    for(int i = 0; i <nodeCount; i++)
    {
        SendKeys.Send("Control");
        tvTestGroups.SelectedNode = tvTestGroups.Nodes[i];
    }

Author:Dumbo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11931752/simulating-a-modifier-key-holding-in-winforms
yy