From fd96ce3403f0bf98c215152e0d8424673c9db7e6 Mon Sep 17 00:00:00 2001 From: Dmitrii Morozov Date: Wed, 27 Mar 2024 20:38:37 +0100 Subject: Refactoring --- input/wrapper.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 input/wrapper.go (limited to 'input/wrapper.go') diff --git a/input/wrapper.go b/input/wrapper.go new file mode 100644 index 0000000..d194f20 --- /dev/null +++ b/input/wrapper.go @@ -0,0 +1,49 @@ +package input + +import ( + "fmt" + "io" +) + +const ( + InputType_debug int = 0 + InputType_uinput int = 1 +) + +type Keyboard interface { + KeyDown(key int) error + KeyUp(key int) error + io.Closer +} + +type Mouse interface { + Move(x, y int32) error + LeftPress() error + LeftRelease() error + Wheel(horizontal bool, delta int32) error + io.Closer +} + +func CreateKeyboard(inputType int) (Keyboard, error) { + switch inputType { + case InputType_debug: + return KeyboardEmptyWrapper{}, nil + case InputType_uinput: + uinputKeyboard := new(KeyboardUinputWrapper) + uinputKeyboard.Init() + return uinputKeyboard, nil + } + return nil, fmt.Errorf("Unknown inputType: %d", inputType) +} + +func CreateMouse(inputType int) (Mouse, error) { + switch inputType { + case InputType_debug: + return MouseEmptyWrapper{}, nil + case InputType_uinput: + uinputMouse := new(MouseUinputWrapper) + uinputMouse.Init() + return uinputMouse, nil + } + return nil, fmt.Errorf("Unknown inputType: %d", inputType) +} -- cgit v1.2.3