Hi,
How can I set the mouse position? So change the mouse to a specified
(x,y) on the screen?
Also,
How can I get the location of a window on the screen of which I know the
title?
Thanks.
Hi,
How can I set the mouse position? So change the mouse to a specified
(x,y) on the screen?
Also,
How can I get the location of a window on the screen of which I know the
title?
Thanks.
I assume you are asking about Microsoft Windows. This is a very
specific question which is more related to Windows programming and the
Windows API than Ruby programming. But nonetheless:
require ‘Win32API’
setCursorPos = Win32API.new(“user32”, “SetCursorPos”, [‘I’,‘I’], ‘V’)
setCursorPos.Call(100,100)
require ‘Win32API’
findWindow = Win32API.new(“user32”, “FindWindow”, [‘P’,‘P’], ‘L’)
getClientRect = Win32API.new(“user32”, “GetClientRect”, [‘P’,‘P’], ‘V’)
hwnd = findWindow.Call(nil, ‘name of window here’)
lpRect = " " * 16 # Four LONGs
getClientRect.Call(hwnd, lpRect)
left, top, right, bottom = lpRect.unpack(‘LLLL’)
puts “Left: #{left}, Top: #{top}, Right: #{right}, Bottom: #{bottom}”
Ryan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs