Fire Trigger button from keyboard keys

@raatech91 You haven't really shown what you have tried, or even really need (in detail).

I have tested some of the keyboard nodes, and two wouldn't even install, but the one from node-red-node-pi-gpio sorta worked... at least the Mouse node did, the Keyboard node just repeatedly flipped from connected to not connected. (for that node, the USB Mouse & Keyboard must be connected to the RPi)

Meanwhile... this is a (poorly hacked) add-on to an excellent example from @Steve-Mcl, that he had provided here. It works on the keyboard that is used with whatever runs the dashboard browser.

It might give you something to work with.

image

[{"id":"b732a0c7f2d6d3b4","type":"ui_led","z":"534ee29537236d51","order":3,"group":"a348b0ef9d248038","width":2,"height":2,"label":"","labelPlacement":"left","labelAlignment":"center","colorForValue":[{"color":"#008000","value":"up","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"square","showGlow":true,"name":"","x":830,"y":260,"wires":[]},{"id":"4f4c0499780251e2","type":"ui_led","z":"534ee29537236d51","order":7,"group":"a348b0ef9d248038","width":2,"height":2,"label":"","labelPlacement":"left","labelAlignment":"center","colorForValue":[{"color":"#008000","value":"down","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"square","showGlow":true,"name":"","x":830,"y":340,"wires":[]},{"id":"4b8858eed7f9d5f8","type":"ui_led","z":"534ee29537236d51","order":6,"group":"a348b0ef9d248038","width":2,"height":2,"label":"","labelPlacement":"left","labelAlignment":"center","colorForValue":[{"color":"#008000","value":"right","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"square","showGlow":true,"name":"","x":950,"y":300,"wires":[]},{"id":"f2ccef4bf96840f3","type":"ui_led","z":"534ee29537236d51","order":5,"group":"a348b0ef9d248038","width":2,"height":2,"label":"","labelPlacement":"left","labelAlignment":"center","colorForValue":[{"color":"#008000","value":"left","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"square","showGlow":true,"name":"","x":710,"y":300,"wires":[]},{"id":"6b39130a6aadae20","type":"ui_template","z":"534ee29537236d51","group":"a348b0ef9d248038","name":"","order":1,"width":0,"height":0,"format":"<div id=\"key_press\">Press Arrow Key</div>\n<script type=\"text/javascript\">\n(function(scope) {\n  const _scope = scope;\n  $('body').on(\"keydown\", function(e) { \n            var keyCode = (e || event || {}).keyCode;\n      if(keyCode >= 37 && keyCode <= 40) {\n        _scope.send({payload: keyCode});\n      }\n  });\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":160,"y":280,"wires":[["4f89730c0a377ddb"]]},{"id":"4f89730c0a377ddb","type":"rbe","z":"534ee29537236d51","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":330,"y":280,"wires":[["55b281b79fc39c90"]]},{"id":"83ed5dffb05cae95","type":"function","z":"534ee29537236d51","name":"","func":"msg.payload=\"\"; \nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":220,"wires":[["4f89730c0a377ddb"]]},{"id":"5b6e58ae4cd1fb43","type":"delay","z":"534ee29537236d51","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":530,"y":280,"wires":[["83ed5dffb05cae95"]]},{"id":"55b281b79fc39c90","type":"function","z":"534ee29537236d51","name":"","func":"let key = msg.payload;\nif (key == 37) {\n    msg.payload = \"left\";\n} else if (key == 38) {\n    msg.payload = \"up\";\n} else if (key == 39) {\n    msg.payload = \"right\";\n} else if (key == 40) {\n    msg.payload = \"down\";\n} else {\n    msg.payload = \"\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":340,"wires":[["f2ccef4bf96840f3","b732a0c7f2d6d3b4","4b8858eed7f9d5f8","4f4c0499780251e2","5b6e58ae4cd1fb43","207dcddfb93e5e9e"]]},{"id":"207dcddfb93e5e9e","type":"debug","z":"534ee29537236d51","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":400,"wires":[]},{"id":"a348b0ef9d248038","type":"ui_group","name":"Default","tab":"3316deba5234ba30","order":1,"disp":true,"width":"6","collapse":false},{"id":"3316deba5234ba30","type":"ui_tab","name":"test","icon":"dashboard","disabled":false,"hidden":false}]
2 Likes