diff options
author | Teddy Wing | 2018-08-21 05:45:16 +0200 |
---|---|---|
committer | Teddy Wing | 2018-08-21 06:06:47 +0200 |
commit | 9ebf6a1461f6322691abc5f6547fcf6eb6f2dae4 (patch) | |
tree | e11470629bb6b8c5264c371bcced64b349c26777 /DomeKey.xcodeproj | |
parent | 4e62e8ad7abf833a3d2cb7ddfe01161e91c648ad (diff) | |
download | DomeKey-9ebf6a1461f6322691abc5f6547fcf6eb6f2dae4.tar.bz2 |
HeadphoneKey: Add system for handling dead keys
We need a way to listen for multiple presses of the headphone buttons.
Once a timeout has been reached, the recorded button presses that
happened within the space of the timeout will be those used for
performing an associated action.
We add an enum for headphone buttons to give them an easy name to refer
to.
The default timeout between button presses before an action gets
executed is 1000 milliseconds. This will be customisable later with a
configuration file.
Already pressed "dead" keys within the timeout are stored in
`_key_buffer`. This buffer gets cleared when we run an action. I you've
pressed a headphone button key, we always try to run an action, so this
will always get cleared, even if no mapping action is found.
I decided to start `_key_buffer` with a capacity of 5 at random because
that seemed like more than enough button presses for a single mapping.
handleDeadKey::
- In order to append a `HeadphoneButton` from our enum, I needed to
convert it to an `id` type because `NSArray` doesn't allow anything
else.
- Call `maybeRunAction` with our timeout. Before doing this, make sure
we cancel any previous delayed calls to `maybeRunAction` because they
might be executed before the most recent headphone button press and
thus run the wrong action. Cancelling enables us to only run the
action once the timeout has elapsed after the most recent headphone
button press.
maybeRunAction:
- Just log the headphone button presses for now.
- Remove all presses from `_key_buffer` so to make way for a new key
mapping.
- I'm now thinking I should rename this method to remove the `maybe`.
Since the `performSelector` gets cancelled outside of this method, the
"maybe" doesn't make sense to me here any more.
Diffstat (limited to 'DomeKey.xcodeproj')
0 files changed, 0 insertions, 0 deletions