-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f719495
commit 5db8c7d
Showing
10 changed files
with
116 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package airinput | ||
|
||
import ( | ||
// #include "input.h" | ||
"C" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"regexp" | ||
"strings" | ||
"time" | ||
|
||
"github.com/codeskyblue/comtool" | ||
) | ||
|
||
var goDebug = false | ||
|
||
func dprintf(format string, args ...interface{}) { | ||
if strings.HasSuffix(format, "\n") { | ||
format += "\n" | ||
} | ||
if goDebug { | ||
fmt.Printf(format, args...) | ||
} | ||
} | ||
|
||
func init() { | ||
var id int = -1 | ||
for i := 0; i < 10; i++ { | ||
namePath := fmt.Sprintf("/sys/class/input/event%d/device/name", i) | ||
if !comtool.Exists(namePath) { | ||
break | ||
} | ||
data, err := ioutil.ReadFile(namePath) | ||
if err != nil { | ||
continue | ||
} | ||
name := strings.TrimSpace(string(data)) | ||
dprintf("event%d: name: %s", i, name) | ||
// $name may have Touchscreen and touchscreen | ||
for _, possibleName := range []string{"ouchscreen$", "-tpd$"} { | ||
re := regexp.MustCompile(possibleName) | ||
if re.MatchString(name) { | ||
id = i | ||
break | ||
} | ||
} | ||
if id != -1 { | ||
break | ||
} | ||
} | ||
dprintf("eventid: %d", id) | ||
if id == -1 { | ||
log.Fatal("can autodetect touchpad event") | ||
} | ||
C.input_init(C.CString(fmt.Sprintf("/dev/input/event%d", id))) | ||
} | ||
|
||
// Where show debug info | ||
func Debug(state bool) { | ||
flag := C.int(0) | ||
if state { | ||
flag = C.int(1) | ||
} | ||
goDebug = state | ||
C.set_debug(flag) | ||
} | ||
|
||
// void tap(int x, int y, int duration_msec); | ||
func Tap(x, y int, duration time.Duration) { | ||
msec := int(duration.Nanoseconds() / 1e6) | ||
C.tap(C.int(x), C.int(y), C.int(msec)) | ||
} | ||
|
||
// void drag(int start_x, int start_y, int end_x, int end_y, int num_steps, int msec); | ||
func Drag(startX, startY int, endX, endY int, steps int, duration time.Duration) { | ||
msec := int(duration.Nanoseconds() / 1e6) | ||
C.drag(C.int(startX), C.int(startY), C.int(endX), C.int(endY), C.int(steps), C.int(msec)) | ||
} | ||
|
||
//void pinch(int Ax0, int Ay0, int Ax1, int Ay1, | ||
// int Bx0, int By0, int Bx1, int By1, int num_steps, int msec); | ||
func Pinch(Ax0, Ay0, Ax1, Ay1 int, | ||
Bx0, By0, Bx1, By1 int, steps int, duration time.Duration) { | ||
msec := int(duration.Nanoseconds() / 1e6) | ||
C.pinch(C.int(Ax0), C.int(Ay0), C.int(Ax1), C.int(Ay1), | ||
C.int(Bx0), C.int(By0), C.int(Bx1), C.int(By1), C.int(steps), C.int(msec)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package airinput | ||
|
||
// #include "screen.h" | ||
import "C" | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,27 @@ | ||
// Currently this is a sample | ||
package main | ||
|
||
// #include "input.h" | ||
import "C" | ||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"regexp" | ||
"strings" | ||
"time" | ||
) | ||
import "github.com/codeskyblue/comtool" | ||
|
||
func init() { | ||
var id int = -1 | ||
for i := 0; i < 10; i++ { | ||
namePath := fmt.Sprintf("/sys/class/input/event%d/device/name", i) | ||
if !comtool.Exists(namePath) { | ||
break | ||
} | ||
data, err := ioutil.ReadFile(namePath) | ||
if err != nil { | ||
continue | ||
} | ||
name := strings.TrimSpace(string(data)) | ||
fmt.Printf("event%d: name: %s\n", i, name) | ||
for _, possibleName := range []string{"touchscreen$", "-tpd$"} { | ||
re := regexp.MustCompile(possibleName) | ||
if re.MatchString(name) { | ||
id = i | ||
break | ||
} | ||
} | ||
if id != -1 { | ||
break | ||
} | ||
} | ||
fmt.Println("eventid:", id) | ||
if id == -1 { | ||
log.Fatal("can autodetect touchpad event") | ||
} | ||
C.input_init(C.CString(fmt.Sprintf("/dev/input/event%d", id))) | ||
} | ||
"github.com/netease/airinput/go-airinput" | ||
) | ||
|
||
func main() { | ||
//C.tap(C.int(154), C.int(1082), 5000) // 1000 = 1s | ||
fmt.Println(ScreenSize()) | ||
w, _ := ScreenSize() | ||
fmt.Println(w / 6 * 5) | ||
x, y := C.int(w/6), C.int(300) | ||
//C.drag(x, y, C.int(945), y, 10, 5000) | ||
mx := C.int(w / 2) | ||
C.pinch(x, y, mx, y, C.int(w/6*5), y, mx, y, 5, 1000) | ||
//airinput.Debug(false) | ||
w, h := airinput.ScreenSize() | ||
fmt.Printf("width: %d, height: %d\n", w, h) | ||
|
||
lx, ly := w/6, 300 | ||
mx, my := w/2, ly | ||
rx, ry := w/6*5, ly | ||
|
||
airinput.Pinch(lx, ly, mx, my, | ||
rx, ry, mx, my, 10, time.Second) | ||
|
||
time.Sleep(time.Second * 1) | ||
C.pinch(mx, y, x, y, mx, y, C.int(w/6*5), y, 5, 1000) | ||
|
||
airinput.Pinch(mx, my, lx, ly, | ||
mx, my, rx, ry, 10, time.Second) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@echo off | ||
adb push airtoolbox /data/local/tmp/ | ||
adb shell chmod 755 /data/local/tmp/airtoolbox | ||
adb shell /data/local/tmp/airtoolbox | ||
adb push airinput /data/local/tmp/ | ||
adb shell chmod 755 /data/local/tmp/airinput | ||
adb shell /data/local/tmp/airinput |