Skip to content

Commit

Permalink
Simplify error handling when syncing events
Browse files Browse the repository at this point in the history
  • Loading branch information
bendahl committed May 3, 2018
1 parent c6a3b0c commit 6089bc7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 75 deletions.
18 changes: 3 additions & 15 deletions keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func (vk vKeyboard) KeyPress(key int) error {
return fmt.Errorf("failed to issue the KeyUp event: %v", err)
}

err = syncEvents(vk.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vk.deviceFile)
}

// KeyDown will send the key code passed (see keycodes.go for available keycodes). Note that unless a key release
Expand All @@ -77,11 +73,7 @@ func (vk vKeyboard) KeyDown(key int) error {
return fmt.Errorf("failed to issue the KeyDown event: %v", err)
}

err = syncEvents(vk.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vk.deviceFile)
}

// KeyUp will release the given key passed as a parameter (see keycodes.go for available keycodes). In most
Expand All @@ -97,11 +89,7 @@ func (vk vKeyboard) KeyUp(key int) error {
return fmt.Errorf("failed to issue the KeyUp event: %v", err)
}

err = syncEvents(vk.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vk.deviceFile)
}

// Close will close the device and free resources.
Expand Down
36 changes: 6 additions & 30 deletions mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ func (vRel vMouse) LeftClick() error {
return fmt.Errorf("Failed to issue the KeyUp event: %v", err)
}

err = syncEvents(vRel.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vRel.deviceFile)
}

// RightClick will issue a RightClick
Expand All @@ -115,11 +111,7 @@ func (vRel vMouse) RightClick() error {
return fmt.Errorf("Failed to issue the KeyUp event: %v", err)
}

err = syncEvents(vRel.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vRel.deviceFile)
}

// LeftPress will simulate a press of the left mouse button. Note that the button will not be released until
Expand All @@ -129,11 +121,7 @@ func (vRel vMouse) LeftPress() error {
if err != nil {
return fmt.Errorf("Failed press the left mouse button: %v", err)
}
err = syncEvents(vRel.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vRel.deviceFile)
}

// LeftRelease will simulate the release of the left mouse button.
Expand All @@ -142,11 +130,7 @@ func (vRel vMouse) LeftRelease() error {
if err != nil {
return fmt.Errorf("Failed to release the left mouse button: %v", err)
}
err = syncEvents(vRel.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vRel.deviceFile)
}

// RightPress will simulate the press of the right mouse button. Note that the button will not be released until
Expand All @@ -156,11 +140,7 @@ func (vRel vMouse) RightPress() error {
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
return syncEvents(vRel.deviceFile)
}

// RightRelease will simulate the release of the right mouse button.
Expand All @@ -169,11 +149,7 @@ func (vRel vMouse) RightRelease() error {
if err != nil {
return fmt.Errorf("Failed to release 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
return syncEvents(vRel.deviceFile)
}

// Close closes the device and releases the device.
Expand Down
36 changes: 6 additions & 30 deletions touchpad.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ func (vTouch vTouchPad) LeftClick() error {
return fmt.Errorf("Failed to issue the KeyUp event: %v", err)
}

err = syncEvents(vTouch.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vTouch.deviceFile)
}

func (vTouch vTouchPad) RightClick() error {
Expand All @@ -88,11 +84,7 @@ func (vTouch vTouchPad) RightClick() error {
return fmt.Errorf("Failed to issue the KeyUp event: %v", err)
}

err = syncEvents(vTouch.deviceFile)
if err != nil {
return fmt.Errorf("sync to device file failed: %v", err)
}
return nil
return syncEvents(vTouch.deviceFile)
}

// LeftPress will simulate a press of the left mouse button. Note that the button will not be released until
Expand All @@ -102,11 +94,7 @@ func (vTouch vTouchPad) LeftPress() error {
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
return syncEvents(vTouch.deviceFile)
}

// LeftRelease will simulate the release of the left mouse button.
Expand All @@ -115,11 +103,7 @@ func (vTouch vTouchPad) LeftRelease() error {
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
return syncEvents(vTouch.deviceFile)
}

// RightPress will simulate the press of the right mouse button. Note that the button will not be released until
Expand All @@ -129,11 +113,7 @@ func (vTouch vTouchPad) RightPress() error {
if err != nil {
return fmt.Errorf("Failed to press 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
return syncEvents(vTouch.deviceFile)
}

// RightRelease will simulate the release of the right mouse button.
Expand All @@ -142,11 +122,7 @@ func (vTouch vTouchPad) RightRelease() error {
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
return syncEvents(vTouch.deviceFile)
}

func (vTouch vTouchPad) Close() error {
Expand Down

0 comments on commit 6089bc7

Please sign in to comment.