Update events.js

This commit is contained in:
radmanplays 2024-04-18 08:53:42 +03:30 committed by GitHub
commit cafaa326f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -172,7 +172,7 @@ function register() {
return `${code}\n`;
})
registerBlock(`${categoryPrefix}whenkeypressed`, {
registerBlock(`${categoryPrefix}whenkeydown`, {
message0: 'when %1 key is down %2 %3',
args0: [
{
@ -198,6 +198,32 @@ function register() {
${KEY===""?`${BLOCKS}`:`if (event.keyCode == '${KEY}') { ${BLOCKS}}`}});`;
return `${code}\n`;
})
registerBlock(`${categoryPrefix}whenkeyup`, {
message0: 'when %1 key is up %2 %3',
args0: [
{
"type": "field_dropdown",
"name": "KEY",
"options": keyBoard
},
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "BLOCKS"
}
],
nextStatement: null,
inputsInline: true,
colour: categoryColor,
}, (block) => {
const KEY = block.getFieldValue('KEY')
const BLOCKS = javascriptGenerator.statementToCode(block, 'BLOCKS');
const code = `window.addEventListener("keyup", event => {
${KEY===""?`${BLOCKS}`:`if (event.keyCode == '${KEY}') { ${BLOCKS}}`}});`;
return `${code}\n`;
})
}
const keyBoard = [