SetCursorPosition: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
 (New page: {{Client function}} __NOTOC__ This function sets the current position of the mouse cursor.  ==Syntax== <syntaxhighlight lang="lua"> bool setCursorPosition (int cursorX, int cursorY ) </syntaxhighlight>  ===Required...)  | 
				Fernando187 (talk | contribs)  m (Fix see also)  | 
				||
| (9 intermediate revisions by 8 users not shown) | |||
| Line 5: | Line 5: | ||
==Syntax==  | ==Syntax==  | ||
<syntaxhighlight lang="lua">  | <syntaxhighlight lang="lua">  | ||
bool setCursorPosition (int cursorX, int cursorY )  | bool setCursorPosition ( int cursorX, int cursorY )  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
| Line 22: | Line 22: | ||
function centerCursorFunction()  | function centerCursorFunction()  | ||
     local showing = isCursorShowing ()  |      local showing = isCursorShowing ()  | ||
     if showing   |      if showing then -- if the cursor is showing  | ||
         local screenX, screenY = guiGetScreenSize () --get the screen size in pixels  |          local screenX, screenY = guiGetScreenSize () --get the screen size in pixels  | ||
         setCursorPosition (screenX/2, screenY/2) --set the cursor position to the center of the screen  |          setCursorPosition (screenX/2, screenY/2) --set the cursor position to the center of the screen  | ||
| Line 29: | Line 29: | ||
     end  |      end  | ||
end  | end  | ||
addCommandHandler( "  | addCommandHandler( "cursorpos", centerCursorFunction )  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
==See Also==  | ==See Also==  | ||
{{  | {{Cursor_functions|client}}  | ||
[[hu:setCursorPosition]]  | |||
Latest revision as of 15:11, 6 November 2024
This function sets the current position of the mouse cursor.
Syntax
bool setCursorPosition ( int cursorX, int cursorY )
Required Arguments
- cursorX: Position over the X axis
 - cursorY: Position over the Y axis
 
Returns
Returns true if the position has been successfully set, false otherwise.
Example
This example sets your cursor position to the center of your screen after using the command cursorpos.
function centerCursorFunction()
    local showing = isCursorShowing ()
    if showing then -- if the cursor is showing
        local screenX, screenY = guiGetScreenSize () --get the screen size in pixels
        setCursorPosition (screenX/2, screenY/2) --set the cursor position to the center of the screen
    else
        outputChatBox( "Your cursor is not showing." )
    end
end
addCommandHandler( "cursorpos", centerCursorFunction )