70002748 Implement a select all with CTRL+A keystroke in the web control

Article 70002748
Type HowTo
Product WebJS
Date Added 8/25/2025 12:00:00 AM
Fixed 11.4.5 (8/25/2025 12:00:00 AM)
Submitted by Brendan Fry

Summary

Implement a select all with CTRL+A keystroke in the web control when a user selection command is active

Solution

vdcanvas.vdKeyDown = vdKeyDown;

function vdKeyDown(e) {
            //ctrl + a is pressed
            if (e.ctrlKey && e.keyCode == 65) {
                //prevent default ctrl+a event
                var evt = e ? e : window.event;
                if (evt.preventDefault) evt.preventDefault();
                evt.returnValue = false;
                //get the active action 
                var action = vdcanvas.ActiveAction();
                //and if is user selecting mode
                if (action.IsSelectMode) {
                    //fill the action selection ( action.customData) with all entities of the active layout that their layer is not lock
                    action.customData = [];
                    var layout = vdcanvas.GetActiveLayout();
                    for (var i = 0; i < layout.Entities.Items.length; i++) {
                        var h = layout.Entities.Items[i];
                        var fig = vdcanvas.GetEntityItem(h);
                       //select only the entities that their layer is not lock
                        var layer = vdcanvas.GetEntityItem(fig.Layer);
                        if (layer.Lock) continue;
                        fig.selected = true;//mark the figure as selected
                        action.customData.push(fig);//add the item to action selection
                    }
                    //refresh the screen with all selected entities highlighted
                    action.hide();
                    vdcanvas.ActionDrawEntities(action.customData, true);
                    action.show();
                   
                }
            }
        }

//run a move command waiting from the user to select entities

vdcanvas.scriptCommand.select(null, function (vdcanvas) { vdcanvas.scriptCommand.move(); });

//press Ctrl+A to select all entities of the active layout

Send comments on this topic.