I am using a third-party control (Aspose.Cells.GridWeb). It is basically a web based Excel control. When a user selects a cell, the onCellSelected event is raised by the control.
The thing is, I need to know what key was pressed by the user to cause this event to be raised. I need this information to determine how to handle the event.
I am using JQuery’s keydown event to capture the button clicked.
$(document).keydown(function(event) {
isKeyLastClicked = true;
keyLastClickedId = event.which;
isMouseButtonLastClicked = false;
mouseButtonLastClickedId = null;
});
The problem is that the control’s onCellSelected event is raised BEFORE the keydown event is raised. Is this expected behavior?
Is there any way to get the id of the key before the control’s event is raised?
Thanks in advance.
After a long discussion at the SO chat…
Since binding the
keydownevent does not produce the desired results, you have to alter theonCellSelectedfunction. It should follow the next pattern:cell) is assigned to a (temporary) variable.keydownevent occurs, the key code is checked:ev.whichorev.keyCode) equals a certain key, theonCellSelectedfunction is called again, passing the value of the temporary variable as a first argument.The code would have the following structure. Modify it to suit your application:
Note:
keyCode,charCodeandwhich, see also: http://asquare.net/javascript/tests/KeyCode.html