title: xamarin.forms - event listener for volume up and down keys
body: <p>I am writing an xamarin.forms app and I want to open 'special settings' page when press both volume up and down buttons. </p>
  
  <p>Is there any way to do that in xamarin.forms?</p>
  
  <p>For now, I have done an event listener, which works correctly. Now last thing i need to do is to pass the binding context to Settings Page.</p>
  
  <pre><code>List&lt;Keycode&gt; _pressedKeys = new List&lt;Keycode&gt;();
  
  
          public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
          {
              if(keyCode == Keycode.VolumeDown)
              {
                  _pressedKeys.Add(keyCode);
                  CheckBoth();
                  return true;
              }
  
              if (keyCode == Keycode.VolumeUp)
              {
                  _pressedKeys.Add(keyCode);
                  CheckBoth();
                  return true;
              }
  
  
              return base.OnKeyDown(keyCode, e);
          }
  
          public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
          {
              if (keyCode == Keycode.VolumeDown)
              {
                  _pressedKeys.Remove(keyCode);
  
                  return true;
              }
  
              if (keyCode == Keycode.VolumeUp)
              {
                  _pressedKeys.Remove(keyCode);
  
  
                  return true;
              }
  
              return base.OnKeyUp(keyCode, e);
          }
  
          public void ChangePage()
          {
              ((App)App.Current).ChangeScreen(new SettingsPage());
          }
  
          public void CheckBoth()
          {
              try
              {
                  if (_pressedKeys.Contains(Keycode.VolumeDown) &amp;&amp;
                      _pressedKeys.Contains(Keycode.VolumeUp))
                  {
                      Console.WriteLine("It works!");
                      ((App)App.Current).ChangeScreen(new SettingsPage());
                      _pressedKeys.Clear();
                  }
              }
              catch (Exception e)
              {
                  Console.WriteLine(e);
              }
          }
  </code></pre>
  
  <p>Solved. I added following line:</p>
  
  <pre><code>var vm= App.Current.MainPage.BindingContext as MainViewModel;
  </code></pre>