#==============================================================================
#
# Mouse Script v1 created by: Cybersam, edited by Astro_mech
#
#==============================================================================
module Mouse
$mx = $my = 0
gsm = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
@cursor_pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
module_function
def mouse_global_pos
pos = [0, 0].pack('ll')
if @cursor_pos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def mouse_pos(catch_anywhere = false)
x, y = screen_to_client(*mouse_global_pos)
width, height = client_size
if catch_anywhere or (x >= 0 and y >= 0 and x < width and y < height)
return $mx = x, $my = y
else
return $mx, $my
end
end
def del
if @oldcursor == nil
return
else
@SetClassLong.call(handel ,-12, @oldcursor)
@oldcursor = nil
end
end
end
$scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
$client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
$readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
$findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
def screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if $scr2cli.call(hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def hwnd
game_name = "\0" * 256
$readini.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
return $findwindow.call('RGSS Player',game_name)
end
def client_size
rect = [0, 0, 0, 0].pack('l4')
$client_rect.call(hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end