Skip to content

Commit

Permalink
Open app switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Feb 3, 2021
1 parent 7209a2c commit e1451d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ When the phone is locked, the fingerprint reader serves its normal purpose of un
There are three different commands:
* Tapping the fingerprint reader one time is the same as clicking in the top left corner of the phone. This is where menu, back or home buttons are positioned. That way, instead of reaching the top of the phone, you just tap the fingerprint reader.
* Tapping the fingerprint reader twice (*tap tap*) does the same as pressing the off button of your phone, it just turns off the screen. This is especially convenient when the off button is located at the side of the phone, which makes it hard to reach.
* Holding the fingerprint sensor a bit longer does the same as a home button. That can be useful if your phone doesn't have any buttons at the front.
* Holding the fingerprint sensor a bit longer opens the "recent apps" menu. That makes switching apps easier, especially if your phone doesn't have any buttons at the front.

### Supported phones
Whether or not this works on your phone might not only depend on the model used, but also the operating system. Different variants of Android might not behave in the way this module expects them to.
Expand Down Expand Up @@ -125,7 +125,7 @@ I then combined this method of clicking and a new method to read the system log

If the program is running, it will detect clicks on the fingerprint sensor. This detection might not seem optimal (it basically just scans the `adb logcat` output for certain lines), but it is surprisingly fast. Like, *very* fast.

Whenever an event happens, the program interprets it and either starts a *very fast* click, a *quite fast* screen off or a *quite slow* home button command (this last one still uses the `input` command). And that's exactly what I wanted.
Whenever an event happens, the program interprets it and either starts a *very fast* click, a *quite fast* screen off or a *quite slow* "recent" button command (this last one still uses the `input` command). And that's exactly what I wanted.

### Building
Since this is a [Go](https://golang.org/) program, compiling the code should be quite easy (I promise!). You do need to know the architecture your phone uses, but it's likely `arm64`.
Expand Down
17 changes: 5 additions & 12 deletions cmd/backtap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ func main() {
}
defer touchDevice.Close()

debug("opening home button device")
homeDevice, err := os.OpenFile("/dev/input/event2", os.O_WRONLY, os.ModeDevice)
if err != nil {
panic("opening home button device input file: " + err.Error())
}
defer homeDevice.Close()

// The last time a certain action was performed
var (
lastTapTime time.Time
Expand Down Expand Up @@ -144,24 +137,24 @@ func main() {
started <- true
select {
case <-buttonAbort:
debug("aborted HOME command")
debug("aborted APP_SWITCH command")
return
case <-time.After(250 * time.Millisecond):
debug("Running HOME command")
debug("Running APP_SWITCH command")

backButtonLock.Lock()
backButtonPressed = true
backButtonLock.Unlock()

err := exec.Command("input", "keyevent", "KEYCODE_HOME").Run()
err := exec.Command("input", "keyevent", "KEYCODE_APP_SWITCH").Run()
if err != nil {
panic("pressing home button: " + err.Error())
panic("pressing APP_SWITCH button: " + err.Error())
}
err = input.Vibrate(vibratorDevice, 50)
if err != nil {
panic("cannot vibrate: " + err.Error())
}
debug("Finished HOME command")
debug("Finished APP_SWITCH command")
}
}()

Expand Down
4 changes: 2 additions & 2 deletions module/backtap/module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=backtap
name=backtap
version=v0.15
versionCode=00015
version=v0.16
versionCode=00016
author=xarantolus
description=Enables several gestures when tapping the fingerprint sensor of a Xiaomi Mi Mix 2

0 comments on commit e1451d6

Please sign in to comment.