rumouse 0.0.3

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/lib/darwin.rb +102 -0
  3. data/lib/rumouse.rb +41 -0
  4. data/lib/win32.rb +62 -0
  5. data/lib/x11.rb +0 -0
  6. metadata +60 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1bb0686e834b4f80ae3abb5f0142c6516603e65
4
+ data.tar.gz: 1ca775d063435c6c57d678cd0d5aa95cff767bcc
5
+ SHA512:
6
+ metadata.gz: 7fbce4ecdc0c3ed923ab3b3bb3f538c0c01afc144825283e9f37f37dee7794e4d9dec6295d0db0bda9150cb9238318495a242369b354b5dbef3fd092d85d10dc
7
+ data.tar.gz: 43a99ca1fe48d7bcafbe9c11f37ba2a79f5d10fe911d339c8265d4e2210644af4b364d7f7c612d232619501b8e5d8ea8c756fabfd01f185951eb37fa012eddd2
@@ -0,0 +1,102 @@
1
+ require 'ffi'
2
+
3
+ module CGEvent
4
+ extend FFI::Library
5
+ ffi_lib "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics"
6
+
7
+ class CGPoint < FFI::Struct
8
+ layout :x, :double,
9
+ :y, :double
10
+ end
11
+
12
+ enum :CGEventType, [:kCGEventNull, 0, # Null Event
13
+ :kCGEventLeftMouseDown, 1, # left mouse-down event
14
+ :kCGEventLeftMouseUp, 2, # left mouse-up event
15
+ :kCGEventRightMouseDown, 3, # right mouse-down event
16
+ :kCGEventRightMouseUp, 4, # right mouse-up event
17
+ :kCGEventMouseMoved, 5, # mouse-moved event
18
+ :kCGEventLeftMouseDragged, 6, # left mouse-dragged event
19
+ :kCGEventRightMouseDragged, 7, # right mouse-dragged event
20
+ :kCGEventOtherMouseDown, 25, # other mouse-down event
21
+ :kCGEventOtherMouseUp, 26, # other mouse-up event
22
+ :kCGEventOtherMouseDragged, 27] # other mouse-dragged event
23
+
24
+ enum :CGMouseButton, [:kCGMouseButtonLeft, 0,
25
+ :kCGMouseButtonRight,
26
+ :kCGMouseButtonCenter ]
27
+
28
+ enum :CGEventTapLocation, [:kCGHIDEventTap, 0,
29
+ :kCGSessionEventTap,
30
+ :kCGAnnotatedSessionEventTap ]
31
+
32
+ attach_function :CGEventCreateMouseEvent,
33
+ [:pointer, :CGEventType, CGPoint.by_value, :CGMouseButton],
34
+ :pointer
35
+
36
+ attach_function :CGEventPost,
37
+ [:CGEventTapLocation, :pointer],
38
+ :void
39
+
40
+ attach_function :CGEventCreate,
41
+ [:pointer],
42
+ :pointer
43
+
44
+ attach_function :CGEventGetLocation,
45
+ [:pointer],
46
+ CGPoint.by_value
47
+
48
+ attach_function :CGDisplayPixelsWide,
49
+ [:int],
50
+ :size_t
51
+
52
+ attach_function :CGDisplayPixelsHigh,
53
+ [:int],
54
+ :size_t
55
+
56
+ attach_function :CFRelease,
57
+ [:pointer],
58
+ :void
59
+ end
60
+
61
+ class RuMouse
62
+ def press x, y, button = 1
63
+ case button
64
+ when 1 then mouse_event x, y, :kCGEventLeftMouseDown, :kCGMouseButtonLeft
65
+ when 2 then mouse_event x, y, :kCGEventRightMouseDown, :kCGMouseButtonRight
66
+ end
67
+ end
68
+
69
+ def release x, y, button = 1
70
+ case button
71
+ when 1 then mouse_event x, y, :kCGEventLeftMouseUp, :kCGMouseButtonLeft
72
+ when 2 then mouse_event x, y, :kCGEventRightMouseUp, :kCGMouseButtonRight
73
+ end
74
+ end
75
+
76
+ def move x, y
77
+ mouse_event x, y, :kCGEventMouseMoved, :kCGMouseButtonLeft
78
+ end
79
+
80
+ def position
81
+ event = CGEvent::CGEventCreate nil
82
+ pos = CGEvent::CGEventGetLocation event
83
+ CGEvent::CFRelease event
84
+ { x: pos[:x], y: pos[:y] }
85
+ end
86
+
87
+ def screen_size
88
+ { x: CGEvent::CGDisplayPixelsWide(0),
89
+ y: CGEvent::CGDisplayPixelsHigh(0) }
90
+ end
91
+
92
+ private
93
+
94
+ def mouse_event x, y, type, button
95
+ coord = CGEvent::CGPoint.new
96
+ coord[:x] = x
97
+ coord[:y] = y
98
+ event = CGEvent::CGEventCreateMouseEvent(nil, type, coord, button)
99
+ CGEvent::CGEventPost(:kCGHIDEventTap, event)
100
+ CGEvent::CFRelease(event)
101
+ end
102
+ end
@@ -0,0 +1,41 @@
1
+ require 'rbconfig'
2
+
3
+ class RuMouse
4
+ def press x, y, button = 1
5
+ raise NotImplementedError
6
+ end
7
+
8
+ def release x, y, button = 1
9
+ raise NotImplementedError
10
+ end
11
+
12
+ def click x, y, button = 1, n = 1
13
+ n.times do
14
+ press x, y, button
15
+ release x, y, button
16
+ end
17
+ end
18
+
19
+ def move x, y
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def position
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def screen_size
28
+ raise NotImplementedError
29
+ end
30
+ end
31
+
32
+ os = RbConfig::CONFIG['host_os']
33
+
34
+ case os
35
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
36
+ require 'win32.rb'
37
+ when /darwin|mac os/
38
+ require 'darwin.rb'
39
+ when /linux|bsd/
40
+ require 'x11.rb'
41
+ end
@@ -0,0 +1,62 @@
1
+ require 'ffi'
2
+
3
+ module User32
4
+ extend FFI::Library
5
+ ffi_lib 'user32.dll'
6
+ ffi_convention :stdcall
7
+
8
+ MOUSEEVENTF_ABSOLUTE = 0x8000
9
+ MOUSEEVENTF_LEFTDOWN = 0x0002
10
+ MOUSEEVENTF_LEFTUP = 0x0004
11
+ MOUSEEVENTF_RIGHTDOWN = 0x0008
12
+ MOUSEEVENTF_RIGHTUP = 0x0010
13
+
14
+ class Point < FFI::Struct
15
+ layout :x, :long,
16
+ :y, :long
17
+ end
18
+
19
+ attach_function :SetCursorPos, [:int, :int], :bool
20
+ attach_function :GetCursorPos, [Point], :bool
21
+ attach_function :GetSystemMetrics, [:int], :int
22
+ attach_function :mouse_event, [:uint, :uint, :uint, :uint, :pointer], :void
23
+ end
24
+
25
+ class RuMouse
26
+ def move x, y
27
+ User32::SetCursorPos x, y
28
+ end
29
+
30
+ def press x, y, button = 1
31
+ User32::mouse_event User32::MOUSEEVENTF_ABSOLUTE | button_code(button, true),
32
+ x, y,
33
+ 0, nil
34
+ end
35
+
36
+ def release x, y, button = 1
37
+ User32::mouse_event User32::MOUSEEVENTF_ABSOLUTE | button_code(button, false),
38
+ x, y,
39
+ 0, nil
40
+ end
41
+
42
+ def position
43
+ point = User32::Point.new
44
+ User32::GetCursorPos point
45
+ { x: point[:x], y: point[:y] }
46
+ end
47
+
48
+ def screen_size
49
+ { x: User32::GetSystemMetrics(0),
50
+ y: User32::GetSystemMetrics(1) }
51
+ end
52
+
53
+ private
54
+
55
+ def button_code id, state
56
+ if id == 1 and state then User32::MOUSEEVENTF_LEFTDOWN
57
+ elsif id == 2 and state then User32::MOUSEEVENTF_RIGHTDOWN
58
+ elsif id == 1 and not state then User32::MOUSEEVENTF_LEFTUP
59
+ elsif id == 2 and not state then User32::MOUSEEVENTF_RIGHTUP
60
+ else 0 end
61
+ end
62
+ end
File without changes
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumouse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Kostuchenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.3
27
+ description: Cross-platform solution for simulating mouse events
28
+ email: kstmaks@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/rumouse.rb
34
+ - lib/darwin.rb
35
+ - lib/win32.rb
36
+ - lib/x11.rb
37
+ homepage: https://github.com/kosmaks/rumouse
38
+ licenses: []
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.0.3
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Port of pythons' PyMouse.
60
+ test_files: []