Keypress events
Hi there, Is there any way for me to bind to a keypress event on a link? I want to be able to delete a link by selecting it, then hitting the delete key. As of yet, I've not seen a way I can achieve this.
Any help is appreciated, Ryan
Ryan, I solved this by binding an event to a "keyListener" when a link is selected and when the delete key is pressed deleting the link and turning off the "keyListener". You will need to bind the flowchart "onLinkSelect" and "onLinkUnselect" to these methods. Code:
function linkSelected(linkID) { keyListener(true, linkKeyListener);
return true;
}
function linkUnSelected() { keyListener(false, linkKeyListener);
return true;
}
function linkKeyListener(event) { if (event.key.toLowerCase() == 'delete') { deleteSelectedLink(); } }
function keyListener(activate, callFunction) { if (activate == true) { document.addEventListener('keyup', callFunction); } else { document.removeEventListener('keyup', callFunction); } }