The person who wrote this article is a beginner with a level of ** programming experience of less than 1 year **. I think there are some confusing parts and mistakes, so if you notice it, please leave a comment.
Extension library for operating the mouse from Ruby
--C (describe the library itself) --Ruby (module)
The source code is here
--You can get the coordinates of the mouse cursor and move the cursor. --It is also possible to output left click and right click. --Since it includes C windows.h, it is ** Windows only **. (It has not been verified because I do not have an environment other than Windows, but it is probably so) --Since it is compiled in a 32-bit environment, it does not work on a 64-bit machine . (Verified) ――When the environment is ready, I will raise the 64-bit version. - Please use in an environment where Ruby works **.
require 'mouse'
Or
(If the scripts that use this library are in the same directory)
require_relative 'mouse'
getCursorPosX()
--Get the X coordinate of the cursor.getCursorPosY()
--Get the Y coordinate of the cursor.setCursorPos(x,y)
--Move the cursor position. Specify the X coordinate of the destination as the first argument and the Y coordinate as the second argument.sendMouseEvent(key)
--A method that outputs the virtual key code of the left and right mouse buttons.
--Please pass an integer or the following constant as an argument.
--M_L_DOWN (= 2)
#The state where the left mouse button is pressed
--M_L_RELEASE (= 4)
#Left mouse button released
--M_R_DOWN (= 8)
#Right mouse button pressed
--M_R_RELEASE (= 16)
#Right mouse button releasedgetKeyState(key)
--Checks if a particular mouse or keyboard key is pressed.
--This method will be implemented in the library for operating the keyboard currently under development.
--Returns 0 if the specified key is not pressed, and any other integer if it is pressed.
--Please pass an integer or the constant in the previous section as an argument.is_cursor_moving?(arg = 0.001)
--Compares the cursor positions at the intervals specified in the argument. The unit is seconds.
--The return value is true
if it has been moved, and false
if it has not.
--Therefore, if the value of ʻarg` is large, it may not be possible to correctly determine whether the cursor is moving.Recommended Posts