Detecting alt keypresses in Android app
<p>I want to create keyboard shortcuts in my Android app such that, say, alt-t runs a certain command. I can't seem to figure out how to detect the presence of the alt modifier in the emulator, though.</p>

<p>I've overridden onKeyDown() in my app to look like the following (Scala):</p>

<pre><code>  override def onKeyDown(keycode:Int, event:KeyEvent) =  keycode match {
    case KeyEvent.KEYCODE_B =&gt;
      StatisticsService.map(_.sayBatteryLevel())
      true
    case KeyEvent.KEYCODE_D =&gt;
      StatisticsService.map(_.sayDate())
      true
    case KeyEvent.KEYCODE_S =&gt;
      StatisticsService.map(_.saySignalStrengths())
      true
    case KeyEvent.KEYCODE_T =&gt;
      StatisticsService.map(_.sayTime())
      true
    case _ =&gt; super.onKeyDown(keycode, event)
  }
</code></pre>

<p>That of course matches the plain keys just fine, but not alt-b, alt-t, etc. How can I change the above to match the given alt-modified bindings?</p>

<p>I've searched Google and have tried using event.isAltPressed, but this doesn't work. I've also logged the results of the keypresses, and have noticed that the alt key isn't at all picked up. That is, simply pressing alt does nothing, and pressing alt-t produces identical logs to just t.</p>

<p>This is being tested in the emulator if that makes a difference.</p>

<p>Edit: Not sure how to respond to comments left on my question, but I'm aware that not all devices have alt keys, but that's not an issue here because I'm coding for a custom device that does. The question isn't "what's the most generic way to do this," but "how do I match alt keybindings when the documented methods don't work and no explanation seems to be given in Google's own docs?"</p>

<p>Thanks.</p>
