Skip to content

Commit

Permalink
Add press and release functions to touch pad device
Browse files Browse the repository at this point in the history
  • Loading branch information
bendahl committed Mar 30, 2018
1 parent 99be8e7 commit fdd6f63
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
67 changes: 67 additions & 0 deletions uinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ type TouchPad interface {
// RightClick will issue a right click.
RightClick() error

// LeftPress will simulate a press of the left mouse button. Note that the button will not be released until
// LeftRelease is invoked.
LeftPress() error

// LeftRelease will simulate the release of the left mouse button.
LeftRelease() error

// RightPress will simulate the press of the right mouse button. Note that the button will not be released until
// RightRelease is invoked.
RightPress() error

// RightRelease will simulate the release of the right mouse button.
RightRelease() error

io.Closer
}

Expand Down Expand Up @@ -227,6 +241,59 @@ func (vTouch vTouchPad) RightClick() error {
}
return nil
}
// LeftPress will simulate a press of the left mouse button. Note that the button will not be released until
// LeftRelease is invoked.
func (vTouch vTouchPad) LeftPress() error {
err := sendBtnEvent(vTouch.deviceFile, evBtnLeft, btnStatePressed)
if err != nil {
return fmt.Errorf("Failed press the left mouse button: %v", err)
}
err = syncEvents(vTouch.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
}

// LeftRelease will simulate the release of the left mouse button.
func (vTouch vTouchPad) LeftRelease() error {
err := sendBtnEvent(vTouch.deviceFile, evBtnLeft, btnStateReleased)
if err != nil {
return fmt.Errorf("Failed to release the left mouse button: %v", err)
}
err = syncEvents(vTouch.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
}

// RightPress will simulate the press of the right mouse button. Note that the button will not be released until
// RightRelease is invoked.
func (vRel vTouchPad) RightPress() error {
err := sendBtnEvent(vRel.deviceFile, evBtnRight, btnStatePressed)
if err != nil {
return fmt.Errorf("Failed to press the right mouse button: %v", err)
}
err = syncEvents(vRel.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
}

// RightRelease will simulate the release of the right mouse button.
func (vTouch vTouchPad) RightRelease() error {
err := sendBtnEvent(vTouch.deviceFile, evBtnRight, btnStateReleased)
if err != nil {
return fmt.Errorf("Failed to release the right mouse button: %v", err)
}
err = syncEvents(vTouch.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
}

func (vTouch vTouchPad) Close() error {
return closeDevice(vTouch.deviceFile)
Expand Down
20 changes: 20 additions & 0 deletions uinput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ func TestBasicTouchPadMoves(t *testing.T) {
t.Fatalf("Failed to perform right click. Last error was: %s\n", err)
}

err = absDev.LeftPress()
if err != nil {
t.Fatalf("Failed to perform left key press. Last error was: %s\n", err)
}

err = absDev.LeftRelease()
if err != nil {
t.Fatalf("Failed to perform left key release. Last error was: %s\n", err)
}

err = absDev.RightPress()
if err != nil {
t.Fatalf("Failed to perform right key press. Last error was: %s\n", err)
}

err = absDev.RightRelease()
if err != nil {
t.Fatalf("Failed to perform right key release. Last error was: %s\n", err)
}

err = absDev.Close()
if err != nil {
t.Fatalf("Failed to close device. Last error was: %s\n", err)
Expand Down

0 comments on commit fdd6f63

Please sign in to comment.