uinput-keyboard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10affa386faea155c4dd9aaf1fbe3156acb7efc0
4
+ data.tar.gz: 1a8ac475e5d7f99b2247f1e272ad04893fb9de44
5
+ SHA512:
6
+ metadata.gz: 0ab3074c1b532c3658d4b995b98599560a400c000e821d7bc78eb451cb2945ec067c8850a394fa4b31416ff054e9e5362e7075216bb0f46032487aa21568768c
7
+ data.tar.gz: e59de67c8452bb7ae4fb670f2736e0569ded9bd800b7828386f5db2134b5b51cc073eb55fee0a204d2720a88061039795d911530699cae9b9fd7f933e1efdaff
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build uinput-keyboard-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install uinput-keyboard-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeTask description="Create tag v0.1.0 and build and push uinput-keyboard-0.1.0.gem to Rubygems" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Uinput::Keyboard
2
+
3
+ Ruby wrapper around uinput to create a virtual keyboard.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'uinput-keyboard'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install uinput-keyboard
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'uinput/keyboard'
25
+
26
+ begin
27
+ keymap = Uinput::Keyboard.keymap(rules: 'evdev', model: 'pc104', layout: 'de', variant: 'nodeadkeys')
28
+ keyboard = Uinput::Keyboard.new(keymap)
29
+
30
+ sleep 1 # to give linux time to setup the new device
31
+
32
+ # While a terminal has focus
33
+ keyboard.type('date') # => $ date
34
+ keyboard.tap(:Return) # => Sun Aug 23 22:57:28 CEST 2015
35
+ ensure
36
+ keyboard.destroy if keyboard
37
+ end
38
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,62 @@
1
+ require 'uinput/device'
2
+ require 'xkbcommon'
3
+ require "uinput/keyboard/version"
4
+ require 'uinput/keyboard/factory'
5
+
6
+ module Uinput
7
+ class Keyboard < Device
8
+ class << self
9
+ def keymap(names)
10
+ Xkbcommon::Context.new.keymap_from_names(names)
11
+ end
12
+ end
13
+
14
+ def initialize(keymap, &block)
15
+ @keymap = keymap
16
+ super(&block)
17
+ end
18
+
19
+ attr_accessor :keymap
20
+
21
+ def press(*symbols)
22
+ symbols_to_keys(*symbols).each{ |key| send_key_event(key.scan_code, state: 1) }
23
+ send_syn_event
24
+ end
25
+
26
+ def release(*symbols)
27
+ symbols_to_keys(*symbols).each{ |key| send_key_event(key.scan_code, state: 0) }
28
+ send_syn_event
29
+ end
30
+
31
+ def tap(*symbols)
32
+ press(*symbols)
33
+ release(*symbols)
34
+ end
35
+
36
+ def type(string)
37
+ string_to_symbols(string).each{ |symbols| tap(*symbols) }
38
+ end
39
+
40
+ def send_key_event(scan_code, state: 1)
41
+ send_event(EV_KEY, scan_code, state)
42
+ end
43
+
44
+ private
45
+
46
+ def symbols_to_keys(*names)
47
+ [*names].flat_map{ |name| symbol(name).keys }
48
+ end
49
+
50
+ def string_to_symbols(string)
51
+ string.chars.map{ |char| char_to_symbol(char).name }
52
+ end
53
+
54
+ def symbol(name)
55
+ @keymap.symbols[name.to_sym] or raise Device::Error.new("no keysym '#{name}' in keymap")
56
+ end
57
+
58
+ def char_to_symbol(char)
59
+ @keymap.characters[char] or raise Device::Error.new("no character '#{char}' in keymap")
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ module Uinput
2
+ class Keyboard < Device
3
+ class SystemInitializer < Device::SystemInitializer
4
+ def initialize(keyboard, &block)
5
+ @keyboard = keyboard
6
+ super(&block)
7
+ receive_key_events
8
+ add_all_keys
9
+ end
10
+
11
+ def add_all_keys
12
+ @keyboard.keymap.keys.map(&:scan_code).each{ |key| add_key(key) }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Uinput
2
+ Keyboard_VERSION = "0.1.0"
3
+ end
data/test.rb ADDED
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ require 'bundler/setup'
3
+ require 'uinput/keyboard'
4
+
5
+ begin
6
+ keymap = Uinput::Keyboard.keymap(rules: 'evdev', model: 'pc104', layout: 'de', variant: 'nodeadkeys')
7
+ keyboard = Uinput::Keyboard.new(keymap)
8
+
9
+ sleep 1
10
+
11
+ keyboard.type('date')
12
+ keyboard.tap(:Return)
13
+
14
+ #keyboard.type('Ѣ')
15
+ #('a'..'z').each{ |char| keyboard.tap(char) }
16
+ #keyboard.tap(:UndefinedKeySym)
17
+ ensure
18
+ keyboard.destroy if keyboard
19
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uinput/keyboard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uinput-keyboard"
8
+ spec.version = Uinput::Keyboard_VERSION
9
+ spec.authors = ["Christopher Aue"]
10
+ spec.email = ["mail@christopheraue.net"]
11
+
12
+ spec.summary = %q{Ruby wrapper around uinput to create a virtual keyboard.}
13
+ spec.homepage = "https://github.com/christopheraue/ruby-uinput-keyboard"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.8"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_dependency "uinput-device", "~> 0.1"
22
+ spec.add_dependency "xkbcommon", "~> 0.1"
23
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uinput-keyboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Aue
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: uinput-device
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: xkbcommon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ description:
70
+ email:
71
+ - mail@christopheraue.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rakeTasks"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - lib/uinput/keyboard.rb
84
+ - lib/uinput/keyboard/factory.rb
85
+ - lib/uinput/keyboard/version.rb
86
+ - test.rb
87
+ - uinput-keyboard.gemspec
88
+ homepage: https://github.com/christopheraue/ruby-uinput-keyboard
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.8
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Ruby wrapper around uinput to create a virtual keyboard.
112
+ test_files: []