• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

MMM-KeyBindings: Control your mirror with Amazon Fire Stick Remote and Generic Keyboard Inputs

Scheduled Pinned Locked Moved Utilities
keyboardremote controlfire stick remotebluetooth
34 Posts 13 Posters 16.1k Views 12 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    shbatm Module Developer
    last edited by shbatm Jan 3, 2019, 10:30 PM May 14, 2017, 4:12 PM

    Description:

    MMM-KeyBindings is a Utility Module to accept inputs from an Amazon Fire Stick Remote (or any bluetooth-connected HID device) as well as generic keyboard inputs and pass them to other modules for control.
    0_1494777951798_fire_stick_remote.jpg

    The module can perform basic functions such as turning on/off the screen based on certain remote keys, but the real power is in the ability to send key press notifications to other modules. My plan is to use this to control other plugins such as my fork of @barnabycolby’s MMM-Carousel (Fork w/ Navigation Enabled: MMM-Carousel w/ KeyBindings and MMM-ProfileSwitcher to switch screens based on remote control input. In the future I also plan to add an on-screen menu with functions similar to those found in the MMM-RemoteControl module.

    See the README for full details on the features.

    Download:

    [card:shbatm/MMM-KeyBindings]

    Version 1.3.0 - Updated 3-Jan-2019 - [BREAKING CHANGES] See details here

    1 Reply Last reply Reply Quote 3
    • A Offline
      AgilesChroms
      last edited by Jun 18, 2017, 10:15 AM

      Top module ! :trophy:
      Unfortunately the slides are only visible on the monitor, and not in the browser.
      Have I overlooked something?

      1 Reply Last reply Reply Quote 0
      • S Offline
        shbatm Module Developer
        last edited by Jun 18, 2017, 10:57 AM

        @AgilesChroms First thing I would check: What browser are you using to view the mirror? If using Chrome/Chromium on the browser (or any others with DevTools), please check the console and see if there are any errors (Ctrl+Shift+I). Also, which modules are you using besides KeyBindings? Could you post or message me a snippet of your config file?

        I am using this module with my fork of MMM-Carousel on both the monitor connected to the Pi and a separate browser without issue.

        A 1 Reply Last reply Jun 18, 2017, 11:43 AM Reply Quote 0
        • A Offline
          AgilesChroms @shbatm
          last edited by AgilesChroms Jun 18, 2017, 1:45 PM Jun 18, 2017, 11:43 AM

          @shbatm
          I am using your modules

          It works with Firefox.
          Unfortunately, remote control does not influence the browser

          ///*KeyBindings*/        
                  {
                      module: 'MMM-KeyBindings',
                     //position: "top_bar",
                      config: {
                          // See below for configurable options
                          enabledKeyStates: ["KEY_PRESSED", "KEY_LONGPRESSED"],
                          enableNotifyServer: true,
                          endableRelayServer: true, 	
                          handleKeys: true, //Array of additional keys to handle in this module above the standard set, Reference Mousetrap API for the available key enumerations.
                          evdev: {
                                  enabled: true,
                                  //alias: 'Amazon Fire TV Remote',
                                  bluetooth: 'A0:02:DC:9B:78:6E',
                                  eventPath: '/dev/input/event3',
                                  disableGrab: false,
                                  longPressDuration: 0.7,
                                  rawMode: false
                          },          
                      }
                  },
          /*Carousel*/        
                  {
                      module: 'MMM-Carousel',
                      position: "bottom_bar",
                      config: {
                          showPageIndicators: true,
                          showPageControls: 	true,
                          transitionInterval: 1 * 60 * 1000,
                          ignoreModules: ['alert'],
                          mode: 'slides',
                          slides: [
                              [ { name:'clock', classes:'zoom140', position:"top_center",displayType: "analog",} ],
                              [ { name:'clock', classes:'zoom100', position:"top_left"} , 'MMM-Traffic', 'calendar', 'compliments', 'MMM-WunderGround', 'MMM-Fuel', 'internet-monitor','newsfeed','MMM-DWD-WarnWeather','MMM-FRITZ-Box-Callmonitor'],
                              ['MMM-Globe', 'MMM-WunderGround','MMM-FRITZ-Box-Callmonitor', 'MMM-Callmonitor-Current-Call', 'newsfeed'],
                              [ { name:'clock', classes:'zoom075', position:"top_left"} , 'MMM-WunderGround', 'MMM-DHT-Sensor', 'MMM-FRITZ-Box-Callmonitor', 'MMM-Callmonitor-Current-Call', 'MMM-DWD-WarnWeather'],
                              [ { name:'clock', classes:'zoom100', position:"top_left"} ,'calendar', 'MMM-WunderGround', 'MMM-Fuel', 'MMM-DHT-Sensor', 'MMM-FRITZ-Box-Callmonitor', 'MMM-Callmonitor-Current-Call', 'newsfeed'],
                              ['mmm-weatherchart', 'MMM-Traffic']
           //clock calendar MMM-Fuel MMM-DHT-Sensor MMM-WunderGround MMM-DWD-WarnWeather MMM-FRITZ-Box-Callmonitor MMM-Callmonitor-Current-Call newsfeed internet-monitor                        
                              ],
                          
          /*               slides: 
                          [
                             [   
                                 {
                                     name:'clock', 
                                     classes:'zoom140', 
                                     position:"top_center"
                                 } 
                             ],
                             [   
                                 {
                                     name:'clock', 
                                     classes:'', 
                                     position:"top_left"
                                 }, 
                                 {
                                     name:'calendar', 
                                     position:'top_right'
                                 }, 
                                 {
                                     name: 'MMM-WunderGround',
                                 position:"top_center",
                                 },
                                 'newsfeed'
                             ]
                          ],*/
                              keyBindingsMode: "DEFAULT",
                          keyBindings: { 
                              NextSlide: "ArrowRight", 
                              PrevSlide: "ArrowLeft", 
          //                    Slide0:    "Return",
          //                    Slide1:    "Menu",
          //                    Slide2:    "MediaPreviousTrack",
          //                    Slide3:    "MediaNextTrack"
                          }
                      }
                  },
          

          take a look @ this.screencast

          1 Reply Last reply Reply Quote 0
          • S Offline
            shbatm Module Developer
            last edited by shbatm Jun 18, 2017, 2:11 PM Jun 18, 2017, 1:57 PM

            @AgilesChroms By default, the Carousel module will only respond to remote control keys on the “server’s” screen. This was done so you could pull up the MM in a browser on another computer and navigate separately with a keyboard/mouse. It’s in the plan down the road for multiple remotes on different screens running from one server, but I haven’t made it that far yet.

            EDIT: I’m assuming that when you say browser, you’re talking about a browser on a different computer and not just another window on the server/RPi running MM. The suggestions below are based on that assumption.

            For now:

            First 2 corrections in your config:

            • Remove handleKeys: true, from MMM-KeyBindings, this is for adding extra keyboard keys to bind to.
            • Add "MMM-KeyBindings" to the ignoreModules list in MMM-Carousel (probably doesn’t do anything at the moment, but just future proofing).

            Next, 2 options for a fix:

            1. If you want to control the browser’s slides separately (i.e. from a keyboard attached to that computer):
              • In MMM-KeyBindings config section, add: enableMousetrap: true, which will turn on regular keyboard binding in the browser window.
              • Keyboard key presses only work when the browser is active and focused – usually have to click in the window and make sure it’s active before it will respond. I also had issues with some media keys not being sent to to browser at all-which is why I went with the evdev path in the first place.
              • Optional (and untested, but should work): If you want to use additional keyboard keys other than the standard keys, then in MMM-Carousel config section: add a duplicate entry in the keyBindings section:
                keyBindings: { 
                    NextSlide: "ArrowRight", // Remote Key Name
                    NextSlide: "r",          // Keyboard Key Name
                    PrevSlide: "ArrowLeft",  // Remote Key Name
                    PrevSlide: "l"           // Keyboard Key Name
                },
                
                You’ll also need to add any new “non-default” keys to MMM-KeyBindings:
                handleKeys: [ 'r', 'l' ],
                
            2. If you want the remote to control ALL screens: Remove the following from Line 71 in modules/MMM-Carousel/MMM-Carousel.js
               && payload.Sender === this.instance
              
              • This is a temporary test for now. In the future I will add a config option for the remote to control all instances or just the main screen. At the moment there is no good way to synchronize the screens when just using the Previous/Next navigation (e.g. if your main screen is on Slide 2 and you open a browser to Slide 0 and press next, both will move but one will be on Slide 3 and the other Slide 1).

            Please let me know if this helps / works – still new to MM2 and just starting development of these modules so any feedback or feature requests are more than welcome! I’m glad someone else is able to make use of the modules.

            A 1 Reply Last reply Jun 18, 2017, 7:31 PM Reply Quote 0
            • A Offline
              AgilesChroms @shbatm
              last edited by Jun 18, 2017, 7:31 PM

              @shbatm said in MMM-KeyBindings: Control your mirror with Amazon Fire Stick Remote and Generic Keyboard Inputs:

              keyBindings: {
              NextSlide: “ArrowRight”, // Remote Key Name
              NextSlide: “r”, // Keyboard Key Name
              PrevSlide: “ArrowLeft”, // Remote Key Name
              PrevSlide: “l” // Keyboard Key Name
              },

              Double definition of keys does not work.
              The remote control is ignored!
              Extra buttons on the remote control are handled

              //                keyBindings: { 
                                  NextSlide: "ArrowRight", // Remote Key Name
                                  PrevSlide: "ArrowLeft",  // Remote Key Name
                                  NextSlide: "k",          // Keyboard Key Name         
                                  PrevSlide: "j",           // Keyboard Key Name
                                  Slide0:    "Return",
                                  Slide1:    "Menu",
                                  Slide2:    "MediaPreviousTrack",
                                  Slide3:    "MediaNextTrack"
                              }
                          }
              
              1 Reply Last reply Reply Quote 0
              • S Offline
                shbatm Module Developer
                last edited by Jun 19, 2017, 2:00 AM

                @AgilesChroms - I’m out of town for business, so bear with me since I’m unable to fully test these suggestions.

                To use custom keyboard keys AND the remote, you can also modify the evdevKeymap and handleKeys in the MMM-KeyBindings Config. The module tries to “map” the remote’s key names to more standard keyboard key names and this can be tweaked. For example in the MMM-KeyBindings Config:

                 ...
                 evdevKeymap: {  
                     Home: "KEY_HOMEPAGE", 
                     Enter: "KEY_KPENTER", 
                     j: "KEY_LEFT",          // Change default "ArrowLeft" to "j"
                     k: "KEY_RIGHT",         // Change default "ArrowRight" to "k"
                     ArrowUp: "KEY_UP", 
                     ArrowDown: "KEY_DOWN",
                     Menu: "KEY_MENU", 
                     MediaPlayPause: "KEY_PLAYPAUSE", 
                     MediaNextTrack: "KEY_FASTFORWARD", 
                     MediaPreviousTrack: "KEY_REWIND",
                     Return: "KEY_BACK"
                     },
                 handleKeys: ['j','k']       //  Add the new keys to the keyboard bindings
                

                In MMM-Carousel, you can now use:

                 keyBindings: { NextSlide: "k", PrevSlide: "j", Slide0: "Return", ... }
                

                Side note:

                Something you may also find useful: the evdevKeymap tries to standardize keys, but if it receives a key that isn’t in the map, it will still pass it along. I use this to also control my Mirror via my home automation system using GET requests.

                For example: if you add a keybinding to MMM-Carousel like Slide1: "SomeSlideTitle", you can jump to that slide with a GET request to the following URL:

                http://mirror_ip:8080/MMM-KeyBindings/notify?notification=KEYPRESS&payload=%7B%22KeyState%22%3A%20%22KEY_PRESSED%22%2C%20%22Duration%22%3A%200.0%2C%20%22KeyName%22%3A%20%22SomeSlideTitle%22%7D
                
                // payload parameter is a url-encoded JSON string:
                {"KeyState": "KEY_PRESSED", "Duration": 0.0, "KeyName": "SomeSlideTitle"}
                
                A 1 Reply Last reply Jun 20, 2017, 5:27 PM Reply Quote 0
                • A Offline
                  AgilesChroms @shbatm
                  last edited by Jun 20, 2017, 5:27 PM

                  @shbatm
                  I am now satisfied with the behavior. The screen is now syncron with the browser
                  thank you for your help

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    shbatm Module Developer
                    last edited by Jun 20, 2017, 5:46 PM

                    You are welcome. Glad you made it work and happy to see someone can make use of the module!

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      jchenaud
                      last edited by jchenaud Aug 15, 2018, 8:23 AM Aug 14, 2018, 3:17 PM

                      hey thk for module !

                      i try to use it but i have some problem:

                      i have put that on my conf file .

                      	{
                                  module :  'MMM-KeyBindings' ,
                                  config : {
                      				enableNotifyServer : false 
                                  }
                              },
                      

                      i just want to use a local keyboard for now and i probably change after for remote.
                      and on my module of pages organisation

                      i have put your config :

                      Module.register("Print_text_from_txt",{
                      	curentPage: -1,
                      	defaults: {
                      		updateInterval:  1000,// 30 * 60 * 1000 //reads the file every 30 mins
                      	
                      	
                      
                      
                          /*** defaults ***
                           *
                           *   Add items below to your moduleName.js's `defaults` object
                           *
                           */
                              /*** MMM-KeyBindings STANDARD MAPPING ***/
                              /* Add the "mode" you would like to respond to */
                              keyBindingsMode: "DEFAULT",
                              keyBindings: {
                                  /* Add each key you want to respond to in the form:
                                   *      yourKeyName: "KeyName_from_MMM-KeyBindings"
                                   */
                                  Right: "ArrowRight",
                                  Left: "ArrowLeft",
                                  /* ... */
                              },
                          },
                      
                      /////////////////////////////
                      	start: function(){
                      		this.setupKeyBindings(); //key binding test
                      
                      		this.sendSocketNotification("START", this.config);
                      	},
                      /////////////////////////////
                      notificationReceived: function(notification, payload){
                      		if (this.validateKeyPress(notification, payload)) { return; }
                      		if (notification === "PAGE_NUMBER_IS")
                      		{
                      			this.curentPage = payload
                      			this.sendNotification("PAGE_CHANGED", this.curentPage);
                      		}
                      ///////////////////////////
                      

                      i have clone directory on my module folder.

                      i have one error on console but she not cause by the module

                      TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
                          at updateModuleContent (main.js:206)
                          at main.js:139
                          at new Promise (<anonymous>)
                          at updateDomWithContent (main.js:137)
                          at main.js:119
                          at <anonymous>
                      

                      i have probably miss something but i dont find :(
                      i haven’t notification on console
                      sorry for my bad language
                      and thanks for your help

                      edit:
                      i have miss on Line on config file

                      but notification is not hear and probably never send :(

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 1 / 4
                      • First post
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy