1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
module Mouse
GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
GetWindowRect = Win32API.new('user32', 'GetWindowRect', ['p', 'p'], 'i')
ScreenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
GetClientRect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
GetPrivateProfileStringA = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
FindWindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
def Mouse.pressed?(key)
return (GetAsyncKeyState.call(key) & 0x01) == 1
end
def Mouse.x()
return nil if Mouse.mousePos.nil?
return Mouse.mousePos[0]
end
def Mouse.y()
return nil if Mouse.mousePos.nil?
return Mouse.mousePos()[1]
end
def Mouse.mousePos()
x, y = Mouse.screenToClient(*Mouse.getPos)
width, height = Mouse.clientSize()
if (x.nil? || y.nil?)
return nil
end
if x >= 0 && y >= 0 && x < width && y < height
return x, y
else
return nil
end
end
def Mouse.getPos()
pos = [0, 0].pack('ll')
if GetCursorPos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def Mouse.screenToClient(x, y)
return nil unless x && y
pos = [x, y].pack('ll')
if ScreenToClient.call(getHandle(), pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def Mouse.clientSize()
rect = [0, 0, 0, 0].pack('l4')
GetClientRect.call(getHandle(), rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
def Mouse.getHandle()
gameName = "\0" * 256
GetPrivateProfileStringA.call('Game', 'Title', '', gameName, 255, ".\\Game.ini")
gameName.delete!("\0")
if ($DEBUG)
result = FindWindow.call('RGSS Player', 0)
else
result = FindWindow.call('RGSS Player', gameName)
end
return result
end
end |