rubydotool 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4204b7f5a9a8afcf17f2d34996457fa29fe254150e9fb48c3e57ed1a7e14f849
4
+ data.tar.gz: c45d27723c689f97720775569d3db6ec1a3024ff33087fa66c00c1b4a6b17330
5
+ SHA512:
6
+ metadata.gz: 8dcb3c06002f374cbb9a17c98763429d2acb67498f8ab6aaafe153ef93bc4ec62b20c32875d5ef97e5859b2ccdd9c45fb703937ea3c50434699660f13aa6f049
7
+ data.tar.gz: c9fcdb211db7294bcf9f481ee6436ef0b59ae196c45187f1a221802f36f9462e091c4d8ae722b4c8c9d1c1e00b257c18312cdc5549913bf537959b007efd09b6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gavff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Rubydotool
2
+
3
+ A small Ruby wrapper for `ydotool`.
4
+
5
+ Install `ydotool` with your system package manager, then add the gem:
6
+
7
+ ```ruby
8
+ gem "rubydotool"
9
+ ```
10
+
11
+ ```ruby
12
+ require "rubydotool"
13
+
14
+ Rubydotool.type("Hello from Ruby")
15
+ Rubydotool.key(28)
16
+ Rubydotool.click
17
+ Rubydotool.right_click
18
+ Rubydotool.move(50, -20)
19
+ Rubydotool.move_to(800, 450)
20
+ ```
21
+
22
+ The daemon starts on the first command and stops when the Ruby process exits. `Rubydotool.start` and `Rubydotool.stop` are also available.
23
+
24
+ Keys use Linux input keycodes. Mouse buttons use ydotool button codes. The process needs permission to access `/dev/uinput`.
@@ -0,0 +1,3 @@
1
+ module Rubydotool
2
+ VERSION = "0.1.1"
3
+ end
data/lib/rubydotool.rb ADDED
@@ -0,0 +1,102 @@
1
+ require_relative "rubydotool/version"
2
+
3
+ module Rubydotool
4
+ SOCKET = "/tmp/rubydotool-#{Process.pid}.sock"
5
+
6
+ @pid = nil
7
+
8
+ def self.start
9
+ return if @pid
10
+
11
+ @pid = Process.spawn(
12
+ "ydotoold",
13
+ "-p",
14
+ SOCKET,
15
+ out: File::NULL,
16
+ err: File::NULL
17
+ )
18
+
19
+ sleep 2
20
+ end
21
+
22
+ def self.stop
23
+ return unless @pid
24
+
25
+ Process.kill("TERM", @pid)
26
+ Process.wait(@pid)
27
+ @pid = nil
28
+
29
+ if File.exist?(SOCKET)
30
+ File.delete(SOCKET)
31
+ end
32
+ rescue Errno::ESRCH, Errno::ECHILD
33
+ @pid = nil
34
+ end
35
+
36
+ def self.run(*arguments)
37
+ start
38
+
39
+ environment = {"YDOTOOL_SOCKET" => SOCKET}
40
+
41
+ text_arguments = []
42
+
43
+ arguments.each do |argument|
44
+ text_arguments << argument.to_s
45
+ end
46
+
47
+ worked = system(
48
+ environment,
49
+ "ydotool",
50
+ *text_arguments,
51
+ out: File::NULL
52
+ )
53
+
54
+ sleep 0.1
55
+
56
+ if !worked
57
+ raise "ydotool command failed"
58
+ end
59
+ end
60
+
61
+ def self.type(text)
62
+ run("type", text)
63
+ end
64
+
65
+ def self.key(*keycodes)
66
+ events = []
67
+
68
+ keycodes.each do |keycode|
69
+ events << "#{keycode}:1"
70
+ end
71
+
72
+ keycodes.reverse.each do |keycode|
73
+ events << "#{keycode}:0"
74
+ end
75
+
76
+ run("key", *events)
77
+ end
78
+
79
+ def self.hotkey(*keycodes)
80
+ key(*keycodes)
81
+ end
82
+
83
+ def self.click(button = "0xC0")
84
+ run("click", button)
85
+ end
86
+
87
+ def self.right_click
88
+ run("click", "0xC1")
89
+ end
90
+
91
+ def self.move(x, y)
92
+ run("mousemove", x, y)
93
+ end
94
+
95
+ def self.move_to(x, y)
96
+ run("mousemove", "--absolute", x, y)
97
+ end
98
+ end
99
+
100
+ at_exit do
101
+ Rubydotool.stop
102
+ end
metadata ADDED
@@ -0,0 +1,42 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubydotool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - gavff
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: A small Ruby API for keyboard and mouse input through ydotool.
13
+ executables: []
14
+ extensions: []
15
+ extra_rdoc_files: []
16
+ files:
17
+ - LICENSE
18
+ - README.md
19
+ - lib/rubydotool.rb
20
+ - lib/rubydotool/version.rb
21
+ homepage: https://github.com/gavff64/rubydotool
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 4.0.18
40
+ specification_version: 4
41
+ summary: A small Ruby wrapper for ydotool
42
+ test_files: []