From 6089bc7274d97df4c916d1fd1d0ecd55fa85b9ea Mon Sep 17 00:00:00 2001 From: Benjamin Dahlmanns Date: Thu, 3 May 2018 22:06:38 +0200 Subject: [PATCH] Simplify error handling when syncing events --- keyboard.go | 18 +++--------------- mouse.go | 36 ++++++------------------------------ touchpad.go | 36 ++++++------------------------------ 3 files changed, 15 insertions(+), 75 deletions(-) diff --git a/keyboard.go b/keyboard.go index 15da476..f3d276d 100644 --- a/keyboard.go +++ b/keyboard.go @@ -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 @@ -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 @@ -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. diff --git a/mouse.go b/mouse.go index 0ede3f8..d7bccbd 100644 --- a/mouse.go +++ b/mouse.go @@ -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 @@ -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 @@ -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. @@ -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 @@ -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. @@ -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. diff --git a/touchpad.go b/touchpad.go index c680b24..faa36cb 100644 --- a/touchpad.go +++ b/touchpad.go @@ -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 { @@ -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 @@ -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. @@ -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 @@ -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. @@ -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 {