wui 0.0.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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +1 -0
- data/lib/wui/version.rb +3 -0
- data/lib/wui.rb +119 -0
- data/wui.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjA5NjUxODQzYTI2ZmRhZWU0Yjk0NjAxYmI4MzgwOGFjNTZkMDE3OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzE5NzkyMmViMGE3ZDEzNTRlMjlkM2FkNjM3OGZhYTg4ZGRlMTQ5OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODA5MTk3NjExZWY5MTk0NzIyZTgwZWY2ODZmODFjN2Y0ZTZjNTZjZjYxNTQ0
|
10
|
+
NDRlMGRmMzc5MGFlOTQwYjdkNThmZjY3NGI3YjQwMDEyZWI5NTNhMjRjMmQz
|
11
|
+
ODMzYTQ1YzkxYWI4MTgzY2Q3MzJlMTQ3MTk3ZDhiZGI2NzIxODE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDUxMjBkNGEyYzEyZDY1Zjk4ZjE1ZmI2NmUwMjMwOTgwZjZhNjc1NmE5Yjc3
|
14
|
+
YTJiZTcyMmRlMmVkM2E5MDBkOTQ4MDY5YTAxZjk4N2JjNjZmYTMwZjY1NjY2
|
15
|
+
M2RhYjYzZGJjZDg1YWQ1ZTY0MTg5NmU3ODYyZDQwMWNlZjBjZGQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 syon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Wui
|
2
|
+
|
3
|
+
Windows UI controls for Ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'wui'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install wui
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'wui'
|
23
|
+
|
24
|
+
# Window Control
|
25
|
+
w = Wui::Window.new
|
26
|
+
|
27
|
+
w.active("G..gle Chrome")
|
28
|
+
w.setPos(100, 100)
|
29
|
+
w.setSize(500, 500)
|
30
|
+
|
31
|
+
# Mouse Control
|
32
|
+
m = Wui::Mouse.new
|
33
|
+
|
34
|
+
m.click
|
35
|
+
|
36
|
+
p m.getPos
|
37
|
+
# => {:x=>510, :y=>490}
|
38
|
+
|
39
|
+
m.setPos(100, 100) # Absolute X, Y
|
40
|
+
m.warp(100, 100) # alias setPos
|
41
|
+
m.to(100, 100) # alias setPos
|
42
|
+
|
43
|
+
m.move(50, 50) # Relative X, Y
|
44
|
+
|
45
|
+
# Method Chain
|
46
|
+
m.to(0, 0).click.to(200, 0).click.move(0, 200).move(200, 0).move(0, 200)
|
47
|
+
|
48
|
+
# o
|
49
|
+
(-180).step(180, 10).each do |i|
|
50
|
+
x = (20 * Math.sin(i * Math::PI / 180.0)).to_i
|
51
|
+
y = (20 * Math.cos(i * Math::PI / 180.0)).to_i
|
52
|
+
m.move(x, y)
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/wui/version.rb
ADDED
data/lib/wui.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require "wui/version"
|
2
|
+
require 'dl/import'
|
3
|
+
require 'easing'
|
4
|
+
|
5
|
+
module Wui
|
6
|
+
|
7
|
+
extend DL::Importer
|
8
|
+
dlload 'User32'
|
9
|
+
extern 'int GetForegroundWindow()'
|
10
|
+
extern 'void SetForegroundWindow(int)'
|
11
|
+
extern 'int EnumWindows(void*, int)'
|
12
|
+
extern 'int GetWindowText(int, char*, int)'
|
13
|
+
extern 'int SetWindowPos(int, int, int, int, int, int, int)'
|
14
|
+
extern 'void GetCursorPos(char*)'
|
15
|
+
extern 'void SetCursorPos(int, int)'
|
16
|
+
extern 'void mouse_event(int, int, int, int, int)'
|
17
|
+
|
18
|
+
class Window
|
19
|
+
def active(title)
|
20
|
+
setWindowHandle(title)
|
21
|
+
checkHWND
|
22
|
+
Wui.SetForegroundWindow(@hWnd)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def setPos(x, y)
|
27
|
+
checkHWND
|
28
|
+
Wui.SetWindowPos(@hWnd, 0, x, y, 0, 0, 1) # SWP_NOSIZE
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def setSize(w, h)
|
33
|
+
checkHWND
|
34
|
+
Wui.SetWindowPos(@hWnd, 0, 0, 0, w, h, 2) # SWP_NOMOVE
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def checkHWND
|
41
|
+
@hWnd = Wui.GetForegroundWindow() if @hWnd.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def getWindowText(hWnd)
|
45
|
+
buf = ' '*128
|
46
|
+
Wui.GetWindowText(hWnd, buf, buf.size) # title -> buf
|
47
|
+
buf
|
48
|
+
end
|
49
|
+
|
50
|
+
def setWindowHandle(title)
|
51
|
+
@hWnd = nil
|
52
|
+
@query = title
|
53
|
+
@ewProc = DL::Function.new(DL::CFunc.new(0, DL::TYPE_INT), [DL::TYPE_INT], &method(:ewProcCallback))
|
54
|
+
Wui.EnumWindows(@ewProc, 0)
|
55
|
+
end
|
56
|
+
|
57
|
+
def ewProcCallback(hWnd)
|
58
|
+
text = getWindowText(hWnd)
|
59
|
+
if /#{@query}/ =~ text
|
60
|
+
@hWnd = hWnd
|
61
|
+
@title = text.strip
|
62
|
+
0 # zero to stop
|
63
|
+
else
|
64
|
+
-1 # continue EnumWindows loop
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Mouse
|
70
|
+
|
71
|
+
def getPos
|
72
|
+
lpP=" "*8
|
73
|
+
Wui.GetCursorPos(lpP)
|
74
|
+
xy = lpP.unpack("LL")
|
75
|
+
{:x=> xy[0], :y=> xy[1]}
|
76
|
+
end
|
77
|
+
|
78
|
+
def setPos(x, y)
|
79
|
+
Wui.SetCursorPos(x, y)
|
80
|
+
self
|
81
|
+
end
|
82
|
+
|
83
|
+
alias warp setPos
|
84
|
+
alias to setPos
|
85
|
+
|
86
|
+
def move(dx, dy)
|
87
|
+
easePos(dx, dy, false)
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def click
|
92
|
+
mouseEvent(0x0002) # MOUSEEVENTF_LEFTDOWN
|
93
|
+
sleep 0.2
|
94
|
+
mouseEvent(0x0004) # MOUSEEVENTF_LEFTUP
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def easePos(x, y, abs=true)
|
101
|
+
d = 20
|
102
|
+
from = getPos
|
103
|
+
if abs
|
104
|
+
xm = (0..d).map { |t| Easing.ease_in_out_expo(t, from[:x], x-from[:x], d) }
|
105
|
+
ym = (0..d).map { |t| Easing.ease_in_out_expo(t, from[:y], y-from[:y], d) }
|
106
|
+
else
|
107
|
+
xm = (0..d).map { |t| Easing.ease_in_out_expo(t, from[:x], x, d) }
|
108
|
+
ym = (0..d).map { |t| Easing.ease_in_out_expo(t, from[:y], y, d) }
|
109
|
+
end
|
110
|
+
(0..d).map { |t| sleep 0.01; Wui.SetCursorPos(xm[t], ym[t]) }
|
111
|
+
self
|
112
|
+
end
|
113
|
+
|
114
|
+
def mouseEvent(event, x=0, y=0, w=0)
|
115
|
+
Wui.mouse_event(event, x, y, w, 0)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
data/wui.gemspec
ADDED
@@ -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 'wui/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wui"
|
8
|
+
spec.version = Wui::VERSION
|
9
|
+
spec.authors = ["syon"]
|
10
|
+
spec.email = ["syon.xiii@gmail.com"]
|
11
|
+
spec.summary = %q{Windows UI controls for Ruby}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/syon/wui"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- syon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-11 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- syon.xiii@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/wui.rb
|
54
|
+
- lib/wui/version.rb
|
55
|
+
- wui.gemspec
|
56
|
+
homepage: https://github.com/syon/wui
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Windows UI controls for Ruby
|
80
|
+
test_files: []
|