KeyTable: Providing a way to determine if shift/meta/ctl/alt was pressed during an event
KeyTable: Providing a way to determine if shift/meta/ctl/alt was pressed during an event
linux_vk
Posts: 1Questions: 0Answers: 0
At the moment, it seems impossible to determine if, say, the shift-key was pressed when the focus event was triggered without editing KeyTable.js. In fact, "function _fnKey ( e )" explicitly ignores events when meta/alt/ctrl are pressed:
[code]
/* If a modifier key is pressed (exapct shift), ignore the event */
if ( e.metaKey || e.altKey || e.ctrlKey )
{
return true;
}[/code]
Since I only care about the shift-key (I want to write code to be able to select multiple cells), I created a public variable inside KeyTable.js and simply set it as follows below the above code:
[code]shiftPressed = e.shiftKey ;[/code]
Thus, I can do something as simple as:
[code]keys.event.focus(null, null, function() {
if (keys.shiftPressed) { alert("Hey, you shift-clicked!") ; } }) ;[/code]
It'd be nice if something cleaner than that was folded into KeyTable at some point. At the moment, it seems like simply writing something like this won't work:
[code]keys.event.focus(null, null, function(e) {
if (e.shiftKey) { alert("Hey, you shift-clicked!") ; } }) ;[/code]
Though I could simply use something like:
[code]$('#tableName td').click(function(e) {
if (e.shiftKey) { alert("Hey, you shift-clicked!") ; } }) ;[/code]
that wouldn't let me take advantage of the fine KeyTable functions like fnGetPosition.
[code]
/* If a modifier key is pressed (exapct shift), ignore the event */
if ( e.metaKey || e.altKey || e.ctrlKey )
{
return true;
}[/code]
Since I only care about the shift-key (I want to write code to be able to select multiple cells), I created a public variable inside KeyTable.js and simply set it as follows below the above code:
[code]shiftPressed = e.shiftKey ;[/code]
Thus, I can do something as simple as:
[code]keys.event.focus(null, null, function() {
if (keys.shiftPressed) { alert("Hey, you shift-clicked!") ; } }) ;[/code]
It'd be nice if something cleaner than that was folded into KeyTable at some point. At the moment, it seems like simply writing something like this won't work:
[code]keys.event.focus(null, null, function(e) {
if (e.shiftKey) { alert("Hey, you shift-clicked!") ; } }) ;[/code]
Though I could simply use something like:
[code]$('#tableName td').click(function(e) {
if (e.shiftKey) { alert("Hey, you shift-clicked!") ; } }) ;[/code]
that wouldn't let me take advantage of the fine KeyTable functions like fnGetPosition.
This discussion has been closed.