Dashboard slider control via arrow keys on physical keyboard

9PsJTX0TlD

Demo flow...

[{"id":"d65b91c9dd547fab","type":"ui_template","z":"e78eac1c.8b9cf","group":"a348b0ef9d248038","name":"","order":7,"width":0,"height":0,"format":"<div id=\"key_press\">waiting key</div>\n<script type=\"text/javascript\">\n(function(scope) {\n  const _scope = scope;\n  $('body').on(\"keyup\", function(e) { \n      var keyCode = (e || event || {}).keyCode;\n      if(keyCode >= 37 && keyCode <= 40) {\n        $(\"#key_press\").text(\"Detected Key: \" + keyCode);\n        _scope.send({payload: keyCode});\n      } \n  });\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":1660,"y":160,"wires":[["e14a22ea0530cff0"]]},{"id":"78be99a6182b7071","type":"debug","z":"e78eac1c.8b9cf","name":"to PMW","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2260,"y":220,"wires":[]},{"id":"ca2131e3bc9252ca","type":"ui_slider","z":"e78eac1c.8b9cf","name":"","label":"slider","tooltip":"","group":"a348b0ef9d248038","order":1,"width":0,"height":0,"passthru":false,"outs":"all","topic":"topic","topicType":"msg","min":"16","max":"24","step":"0.5","className":"","x":1850,"y":280,"wires":[["739ea32e3e567e19"]]},{"id":"739ea32e3e567e19","type":"change","z":"e78eac1c.8b9cf","name":"","rules":[{"t":"set","p":"slider","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2020,"y":280,"wires":[["78be99a6182b7071"]]},{"id":"e14a22ea0530cff0","type":"change","z":"e78eac1c.8b9cf","name":"get slider value","rules":[{"t":"set","p":"slider","pt":"msg","to":"slider","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1840,"y":160,"wires":[["f78440de5e7b323e"]]},{"id":"f78440de5e7b323e","type":"function","z":"e78eac1c.8b9cf","name":"inc/dec/dheck","func":"const MIN = 16;\nconst MAX = 24;\nconst INC = 0.5;\n\nlet slider = msg.slider || MIN;\n\nswitch(msg.payload) {\n    case 37:\n        //left arrow\n        slider -= INC;\n    break;\n    \n    case 39:\n        //right arrow\n        slider += INC;\n    break;\n}\n\nif (slider < MIN) {\n    slider = MIN;\n} else if (slider > MAX) {\n    slider = MAX;\n}\n\nmsg.payload = slider;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2020,"y":160,"wires":[["c93e8a8710414bed","78be99a6182b7071"]]},{"id":"c93e8a8710414bed","type":"change","z":"e78eac1c.8b9cf","name":"","rules":[{"t":"set","p":"slider","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1680,"y":280,"wires":[["ca2131e3bc9252ca"]]},{"id":"a348b0ef9d248038","type":"ui_group","name":"Default","tab":"3316deba5234ba30","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"3316deba5234ba30","type":"ui_tab","name":"test","icon":"dashboard","disabled":false,"hidden":false}]