How can I detect a keypress in blockly and see which key it was?

539 views
Skip to first unread message

Zubair Quraishi

unread,
Aug 24, 2016, 1:03:12 AM8/24/16
to Blockly
I wish to detect when the enter key is pressed in blockly so that I can trigger a code evaluation, but I can't figure out how to detect key presses in Blockly. I see the event code such as the following:

function onFirstComment(event) {
 
if (event.type == Blockly.Events.CHANGE &&
     
event.element == 'comment' &&
     
!event.oldValue && event.newValue) {
    alert
('Congratulations on creating your first comment!')
    workspace
.removeChangeListener(onFirstComment);
 
}
}
workspace
.addChangeListener(onFirstComment);

but the Blockly.Events.XXX only allows the following values:

One of Blockly.Events.CREATE, Blockly.Events.DELETE, Blockly.Events.CHANGE, Blockly.Events.MOVE, Blockly.Events.UI

Is there any way to drill in to one of these events and find out which key was pressed?

Zubair Quraishi

unread,
Aug 28, 2016, 3:22:46 AM8/28/16
to Blockly
just a quick update on this. i know I did not receive any replies on this thread but I have been informed that it is not possible to find out which key was pressed, not without modifying the blockly code itself. As a workaround I make a guess as to when enter is pressed by saying that if no key is pressed for 1 second then enter has probably been pressed.

Juan Carlos Orozco

unread,
Oct 29, 2016, 9:18:02 AM10/29/16
to Blockly

Zubair Quraishi

unread,
Oct 31, 2016, 1:32:04 AM10/31/16
to Blockly
Thanks Juan. I figured out another way in the end and and develping it here with ablockly database builder:

https://github.com/zubairq/yazz
Reply all
Reply to author
Forward
0 new messages