Introductory Mouse Input functionality guide
Written by: Various Authors
Last updated: October 2024
Here are some functions that are used to handle mouse button inputs. These functions all use SplashKit’s Mouse Button data type for the argument and check if the specified button has been clicked, held down, or released.
Mouse Button is an enumeration used by SplashKit to read inputs from the mouse. Understanding how to handle mouse buttons is crucial for developers who want users to control their programs using the mouse.
Description Enum Value in Code No mouse button NO_BUTTON The left mouse button LEFT_BUTTON The middle mouse button MIDDLE_BUTTON The right mouse button RIGHT_BUTTON The x1 mouse button MOUSE_X1_BUTTON The x2 mouse button MOUSE_X2_BUTTON
Description Enum Value in Code No mouse button MouseButton.NoButton The left mouse button MouseButton.LeftButton The middle mouse button MouseButton.MiddleButton The right mouse button MouseButton.RightButton The x1 mouse button MouseButton.MouseX1Button The x2 mouse button MouseButton.MouseX2Button
Description Enum Value in Code No mouse button MouseButton.no_button The left mouse button MouseButton.left_button The middle mouse button MouseButton.middle_button The right mouse button MouseButton.right_button The x1 mouse button MouseButton.mouse_x1_button The x2 mouse button MouseButton.mouse_x2_button
Mouse Clicked
Mouse Clicked is a boolean function that checks if the specified Mouse Button
has been clicked since the last time Process Events was called.
Here is a simple example using the left and right mouse buttons:
open_window ( " Mouse Inputs " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Inputs " ))
// process user input events
// change screen colour to red if left mouse button is clicked
if ( mouse_clicked (LEFT_BUTTON))
// change screen colour to yellow if right mouse button is clicked
else if ( mouse_clicked (RIGHT_BUTTON))
clear_screen (COLOR_YELLOW);
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Inputs " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Inputs " ))
// process user input events
// change screen colour to red if left mouse button is clicked
if ( MouseClicked ( MouseButton . LeftButton ))
// change screen colour to yellow if right mouse button is clicked
else if ( MouseClicked ( MouseButton . RightButton ))
ClearScreen ( ColorYellow ());
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Inputs " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
if ( SplashKit . MouseClicked ( MouseButton . LeftButton ))
SplashKit . ClearScreen ( Color . Red );
else if ( SplashKit . MouseClicked ( MouseButton . RightButton ))
SplashKit . ClearScreen ( Color . Yellow );
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
COLOR_YELLOW = color_yellow ()
COLOR_WHITE = color_white ()
win = open_window ( " Mouse Inputs " , 800 , 600 )
current_color = COLOR_WHITE
while not window_close_requested ( win ):
# Process user input events
# Check mouse click status and change screen color
if mouse_clicked ( MouseButton.left_button ):
current_color = COLOR_RED # Change color to red
elif mouse_clicked ( MouseButton.right_button ):
current_color = COLOR_YELLOW # Change color to yellow
# Clear screen with the current color
clear_screen ( current_color )
if __name__ == " __main__ " :
Mouse Down
Mouse Down checks if the specified button is being held down.
Here is a simple example using the left and right mouse buttons:
open_window ( " Mouse Inputs " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Inputs " ))
// process user input events
// change screen colour to red if left mouse button is held down
if ( mouse_down (LEFT_BUTTON))
// change screen colour to yellow if right mouse button is held down
else if ( mouse_down (RIGHT_BUTTON))
clear_screen (COLOR_YELLOW);
// change screen colour to white if no mouse button held down
clear_screen (COLOR_WHITE);
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Inputs " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Inputs " ))
// process user input events
// change screen colour to red if left mouse button is held down
if ( MouseDown ( MouseButton . LeftButton ))
// change screen colour to yellow if right mouse button is held down
else if ( MouseDown ( MouseButton . RightButton ))
ClearScreen ( ColorYellow ());
// change screen colour to white if no mouse button held down
ClearScreen ( ColorWhite ());
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Inputs " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
if ( SplashKit . MouseDown ( MouseButton . LeftButton ))
SplashKit . ClearScreen ( Color . Red );
else if ( SplashKit . MouseDown ( MouseButton . RightButton ))
SplashKit . ClearScreen ( Color . Yellow );
SplashKit . ClearScreen ( Color . White );
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
COLOR_YELLOW = color_yellow ()
COLOR_WHITE = color_white ()
window = open_window ( " Mouse Inputs " , 800 , 600 )
current_color = COLOR_WHITE
while not window_close_requested ( window ):
# Process user input events
# Check mouse button status and change screen color
if mouse_down ( MouseButton.left_button ):
current_color = COLOR_RED # Change color to red
elif mouse_down ( MouseButton.right_button ):
current_color = COLOR_YELLOW # Change color to yellow
current_color = COLOR_WHITE # Default color if no mouse button is held down
clear_screen ( current_color )
if __name__ == " __main__ " :
Mouse Up
Opposite to the previous function, Mouse Up checks if the specified button is released.
Here is a simple example using the left mouse button:
open_window ( " Mouse Inputs " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Inputs " ))
// process user input events
// change screen colour to red if left mouse button is not pressed
if ( mouse_up (LEFT_BUTTON))
// change screen colour to white if left button is pressed
clear_screen (COLOR_WHITE);
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Inputs " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Inputs " ))
// process user input events
// change screen colour to red if left mouse button is not pressed
if ( MouseUp ( MouseButton . LeftButton ))
// change screen colour to white if left button is pressed
ClearScreen ( ColorWhite ());
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Inputs " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
if ( SplashKit . MouseUp ( MouseButton . LeftButton ))
SplashKit . ClearScreen ( Color . Red );
SplashKit . ClearScreen ( Color . White );
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
COLOR_WHITE = color_white ()
window = open_window ( " Mouse Inputs " , 800 , 600 )
while not window_close_requested ( window ):
# Process user input events
# Change screen color to red if the left mouse button is not pressed
if not mouse_down ( MouseButton.left_button ):
# Change screen color to white if the left button is pressed
clear_screen ( COLOR_WHITE )
if __name__ == " __main__ " :
Mouse Movement Functionality
Another thing we can do with mouse input, other than checking button presses, is to check mouse movement in the program.
Mouse Movement
Mouse Movement is a function that returns the amount of accumulated mouse movement since the last time Process Events
was called. It returns the value as a Vector 2D
data type, which shows the direction and distance in the x and y scale.
Here is an example using the left mouse button combined with horizontal movement to change the hue of the screen colour, and the right mouse button combined with vertical movement to change the saturation of the screen colour:
// mouse movement variable
open_window ( " Mouse Movement " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Movement " ))
// process user input events
// store the mouse movement direction and distance to the movement variable
movement = mouse_movement ();
// change screen colour 'hue' if left mouse button is held down
if ( mouse_down (LEFT_BUTTON))
// change hue of screen colour based on horizontal mouse movement
hue += movement . x / screen_width ();
// change screen colour 'saturation' if right mouse button is held down
if ( mouse_down (RIGHT_BUTTON))
// change saturation of screen colour based on vertical mouse movement
saturation += movement . y / screen_height ();
// display current screen colour
clear_screen ( hsb_color (hue, saturation, brightness));
using static SplashKitSDK . SplashKit;
// mouse movement variable
OpenWindow ( " Mouse Movement " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Movement " ))
// process user input events
// store the mouse movement direction and distance to the movement variable
movement = MouseMovement ();
// change screen colour 'hue' if left mouse button is held down
if ( MouseDown ( MouseButton . LeftButton ))
// change hue of screen colour based on horizontal mouse movement
hue += movement . X / ScreenWidth ();
// change screen colour 'saturation' if right mouse button is held down
if ( MouseDown ( MouseButton . RightButton ))
// change saturation of screen colour based on vertical mouse movement
saturation += movement . Y / ScreenHeight ();
// display current screen colour
ClearScreen ( HSBColor (hue, saturation, brightness));
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Movement " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
Vector2D movement = SplashKit . MouseMovement ();
if ( SplashKit . MouseDown ( MouseButton . LeftButton ))
hue += movement . X / SplashKit . ScreenWidth ();
if ( SplashKit . MouseDown ( MouseButton . RightButton ))
saturation += movement . Y / SplashKit . ScreenHeight ();
SplashKit . ClearScreen ( SplashKit . HSBColor (hue, saturation, brightness));
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window = open_window ( " Mouse Movement " , 800 , 600 )
while not window_close_requested ( window ):
movement = mouse_movement ()
# Update hue and saturation based on mouse movement
if mouse_down ( MouseButton.left_button ):
# Adjust hue based on horizontal mouse movement
hue = (hue + movement.x / window_width ( window )) % 1.0
if mouse_down ( MouseButton.right_button ):
# Adjust saturation based on vertical mouse movement
saturation = min ( max ( saturation + movement.y / window_height ( window ) , 0.0 ) , 1.0 )
# Create the color using HSB values
color = hsb_color ( hue , saturation , brightness )
# Clear the screen with the new color
if __name__ == " __main__ " :
Mouse Wheel Scroll returns the distance and direction of the mouse scroll since the last time Process Events
was called. Like the previous function, this function returns the Vector 2D
data type.
Here is an example using vertical scrolling to change the hue of the screen colour:
open_window ( " Mouse Scrolling " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Scrolling " ))
// process user input events
// store the mouse wheel scroll direction and distance to the scroll variable
scroll = mouse_wheel_scroll ();
// change hue of screen colour based on vertical mouse scrolling (two fingers if using trackpad)
// display current screen colour
clear_screen ( hsb_color (hue, saturation, brightness));
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Scrolling " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Scrolling " ))
// process user input events
// store the mouse wheel scroll direction and distance to the scroll variable
scroll = MouseWheelScroll ();
// change hue of screen colour based on vertical mouse scrolling (two fingers if using trackpad)
// display current screen colour
ClearScreen ( HSBColor (hue, saturation, brightness));
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Scrolling " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
Vector2D scroll = SplashKit . MouseWheelScroll ();
SplashKit . ClearScreen ( SplashKit . HSBColor (hue, saturation, brightness));
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window = open_window ( " Mouse Scrolling " , 800 , 600 )
while not window_close_requested ( window ):
# Process user input events
# Store the mouse wheel scroll direction and distance to the scroll variable
scroll = mouse_wheel_scroll ()
# Change hue of screen color based on vertical mouse scrolling
# Ensure hue is within the valid range [0.0, 1.0]
hue = min ( max ( hue , 0.0 ) , 1.0 )
# Display current screen color
clear_screen ( hsb_color ( hue , saturation , brightness ))
if __name__ == " __main__ " :
Mouse Location Functionality
Now that we have learned how to handle mouse inputs and movements, let’s look at how to
use the mouse’s location in the window, which can be used in your program to make the experience more interactive. Combined with the mouse input functions, it can be used to spawn items where the player clicked or respond to the player clicking where an item is located.
Mouse Position
Mouse Position returns the position of the mouse in the current window as a Point 2d data type, which is its x and y coordinates.
Here is a simple example that draws a circle at the mouse position:
open_window ( " Mouse Location " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Location " ))
// process user input events
// draw blue circle at mouse position
clear_screen (COLOR_WHITE);
fill_circle (COLOR_LIGHT_BLUE, circle_at ( mouse_position (), 20 ));
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Location " ))
// process user input events
// draw blue circle at mouse position
ClearScreen ( ColorWhite ());
FillCircle ( ColorLightBlue (), CircleAt ( MousePosition (), 20 ));
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
SplashKit . ClearScreen ( Color . White );
Point2D mousePosition = SplashKit . MousePosition ();
SplashKit . FillCircle ( Color . LightBlue , mousePosition . X , mousePosition . Y , 20 );
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window = open_window ( " Mouse Location " , 800 , 600 )
while not window_close_requested ( window ):
# Process user input events
# Clear the screen with white color
clear_screen ( color_white ())
# Get the current mouse position
mouse_pos = mouse_position ()
# Draw a blue circle at the current mouse position
fill_circle ( color_light_blue () , mouse_pos.x , mouse_pos.y , 20 )
if __name__ == " __main__ " :
Mouse Position Vector
Mouse Position Vector returns the position of the mouse relative to the window origin as a Vector 2d .
Here is a simple example that displays the mouse position vector as a line:
open_window ( " Mouse Location " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Location " ))
// process user input events
// draw line from mouse position vector
clear_screen (COLOR_WHITE);
draw_line (COLOR_BLUE, line_from ( mouse_position_vector ()));
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Location " ))
// process user input events
// draw line from mouse position vector
ClearScreen ( ColorWhite ());
DrawLine ( ColorBlue (), LineFrom ( MousePositionVector ()));
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
SplashKit . ClearScreen ( Color . White );
SplashKit . DrawLine ( Color . Blue , SplashKit . LineFrom ( SplashKit . MousePositionVector ()));
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window = open_window ( " Mouse Location " , 800 , 600 )
while not window_close_requested ( window ):
# Process user input events
# Clear the screen with white color
clear_screen ( color_white ())
# Get the current mouse position
mouse_pos = mouse_position_vector ()
# Draw a line from the top-left corner to the current mouse position
draw_line ( color_blue () , 0 , 0 , mouse_pos.x , mouse_pos.y )
if __name__ == " __main__ " :
Mouse X
Mouse X returns the distance of the mouse from the left edge of the window.
Here is an example using the left mouse button to drag a “curtain” across the screen from the left side, based on the mouse’s x coordinate:
open_window ( " Mouse Location " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Location " ))
// process user input events
if ( mouse_down (LEFT_BUTTON))
clear_screen (COLOR_WHITE);
fill_circle (COLOR_BLUE, 400 , 300 , 100 );
// draw purple "curtain" from left side of screen to x coordinate of mouse
fill_rectangle (COLOR_PURPLE, 0 , 0 , x, screen_height ());
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Location " ))
// process user input events
if ( MouseDown ( MouseButton . LeftButton ))
ClearScreen ( ColorWhite ());
FillCircle ( ColorBlue (), 400 , 300 , 100 );
// draw purple "curtain" from left side of screen to x coordinate of mouse
FillRectangle ( ColorPurple (), 0 , 0 , x, ScreenHeight ());
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
if ( SplashKit . MouseDown ( MouseButton . LeftButton ))
SplashKit . ClearScreen ( Color . White );
SplashKit . FillCircle ( Color . Blue , 400 , 300 , 100 );
SplashKit . FillRectangle ( Color . Purple , 0 , 0 , x, SplashKit . ScreenHeight ());
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window = open_window ( " Mouse Location " , 800 , 600 )
while not window_close_requested ( window ):
# Process user input events
# Update x-coordinate if the left mouse button is down
if mouse_down ( MouseButton.left_button ):
# Clear the screen with white color
clear_screen ( color_white ())
# Draw a blue circle at the center of the screen
fill_circle ( color_blue () , 400 , 300 , 100 )
# Draw a purple "curtain" from the left side of the screen to the x-coordinate of the mouse
fill_rectangle ( color_purple () , 0 , 0 , x , window_height ( window ))
if __name__ == " __main__ " :
Mouse Y
Mouse Y returns the distance of the mouse from the top edge of the window.
Here is an example using the left mouse button to drag a “curtain/blind” down the screen from the top, based on the mouse’s y coordinate:
open_window ( " Mouse Location " , 800 , 600 );
while ( ! window_close_requested ( " Mouse Location " ))
// process user input events
if ( mouse_down (LEFT_BUTTON))
clear_screen (COLOR_WHITE);
fill_circle (COLOR_BLUE, 400 , 300 , 100 );
// draw purple "curtain" from top of screen to y coordinate of mouse
fill_rectangle (COLOR_PURPLE, 0 , 0 , screen_width (), y);
using static SplashKitSDK . SplashKit;
OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! WindowCloseRequested ( " Mouse Location " ))
// process user input events
if ( MouseDown ( MouseButton . LeftButton ))
ClearScreen ( ColorWhite ());
FillCircle ( ColorBlue (), 400 , 300 , 100 );
// draw purple "curtain" from top of screen to y coordinate of mouse
FillRectangle ( ColorPurple (), 0 , 0 , ScreenWidth (), y);
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Location " , 800 , 600 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
if ( SplashKit . MouseDown ( MouseButton . LeftButton ))
SplashKit . ClearScreen ( Color . White );
SplashKit . FillCircle ( Color . Blue , 400 , 300 , 100 );
SplashKit . FillRectangle ( Color . Purple , 0 , 0 , SplashKit . ScreenWidth (), y);
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window = open_window ( " Mouse Location " , 800 , 600 )
while not window_close_requested ( window ):
# Process user input events
if mouse_down ( MouseButton.left_button ):
# Clear the screen with white color
clear_screen ( color_white ())
# Draw a blue circle at the center of the screen
fill_circle ( color_blue () , 400 , 300 , 100 )
# Draw a purple "curtain" from the top of the screen to the y-coordinate of the mouse
fill_rectangle ( color_purple () , 0 , 0 , window_width ( window ) , y )
if __name__ == " __main__ " :
Mouse Visibility
Finally, we can also alter the mouse visibility on SplashKit. The following functions handles the
mouse visibility. These can be useful to create a more immersive environment for your game.
Hide/Show Mouse
Hide Mouse hides the mouse from the screen. Show Mouse shows the mouse to the screen.
Here is a simple example where the mouse “disappears in a black hole”:
// create cirle variable for "black hole"
open_window ( " Mouse Visibility " , 800 , 600 );
// create black hole in centre of screen
blackHole = circle_at ( screen_center (), 50 );
while ( ! window_close_requested ( " Mouse Visibility " ))
// process user input events
// mouse disappears in black hole
if ( point_in_circle ( mouse_position (), blackHole))
// mouse reappears once out of black hole
// display "black hole" on screen
clear_screen (COLOR_WHITE);
fill_circle (COLOR_BLACK, blackHole);
using static SplashKitSDK . SplashKit;
// create cirle variable for "black hole"
OpenWindow ( " Mouse Visibility " , 800 , 600 );
// create black hole in centre of screen
blackHole = CircleAt ( ScreenCenter (), 50 );
while ( ! WindowCloseRequested ( " Mouse Visibility " ))
// process user input events
// mouse disappears in black hole
if ( PointInCircle ( MousePosition (), blackHole))
// mouse reappears once out of black hole
// display "black hole" on screen
ClearScreen ( ColorWhite ());
FillCircle ( ColorBlack (), blackHole);
namespace MouseVisibility
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Visibility " , 800 , 600 );
Circle blackHole = SplashKit . CircleAt ( SplashKit . ScreenCenter (), 50 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
if ( SplashKit . PointInCircle ( SplashKit . MousePosition (), blackHole))
SplashKit . ClearScreen ( Color . White );
SplashKit . FillCircle ( Color . Black , blackHole);
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window_width, window_height = 800 , 600
window = open_window ( " Mouse Visibility " , window_width , window_height )
black_hole_center = point_at ( window_width / 2 , window_height / 2 )
while not window_close_requested ( window ):
# Process user input events
# Get the current mouse position
mouse_pos = mouse_position ()
# Calculate distance from the mouse to the black hole center
dx = mouse_pos.x - black_hole_center.x
dy = mouse_pos.y - black_hole_center.y
distance = (dx ** 2 + dy ** 2 ) ** 0.5
# Hide or show the mouse based on distance
if distance <= black_hole_radius:
# Clear the screen with white color
clear_screen ( color_white ())
# Draw the black hole as a circle
fill_circle ( color_black () , black_hole_center.x , black_hole_center.y , black_hole_radius )
if __name__ == " __main__ " :
Show Mouse
There are two versions of the Show Mouse function. The first version is shown above. The second version shows or hides the mouse based on its boolean parameter. If true, it shows the mouse, while if false, it hides the mouse from the screen.
Here is a simple example where the mouse is only visible in the “spot light”:
// create cirle variable for emulating a "stage spot light"
open_window ( " Mouse Visibility " , 800 , 600 );
// create a "spot light" circle in centre of screen
spotLight = circle_at ( screen_center (), 100 );
while ( ! window_close_requested ( " Mouse Visibility " ))
// process user input events
// mouse disappears when not in the "spot light"
show_mouse ( point_in_circle ( mouse_position (), spotLight));
// display "spot light" on screen
clear_screen (COLOR_BLACK);
fill_circle (COLOR_ALICE_BLUE, spotLight);
using static SplashKitSDK . SplashKit;
// create cirle variable for emulating a "stage spot light"
OpenWindow ( " Mouse Visibility " , 800 , 600 );
// create a "spot light" circle in centre of screen
spotLight = CircleAt ( ScreenCenter (), 100 );
while ( ! WindowCloseRequested ( " Mouse Visibility " ))
// process user input events
// mouse disappears when not in the "spot light"
ShowMouse ( PointInCircle ( MousePosition (), spotLight));
// display "spot light" on screen
ClearScreen ( ColorBlack ());
FillCircle ( ColorWhite (), spotLight);
namespace MouseVisibility
public static void Main ()
Window window = SplashKit . OpenWindow ( " Mouse Visibility " , 800 , 600 );
Circle spotLight = SplashKit . CircleAt ( SplashKit . ScreenCenter (), 100 );
while ( ! SplashKit . WindowCloseRequested (window))
SplashKit . ProcessEvents ();
bool isMouseInSpotLight = SplashKit . PointInCircle ( SplashKit . MousePosition (), spotLight);
SplashKit . ShowMouse (isMouseInSpotLight);
SplashKit . ClearScreen ( Color . Black );
SplashKit . FillCircle ( Color . White , spotLight);
SplashKit . RefreshScreen ( 60 );
SplashKit . CloseAllWindows ();
window_width, window_height = 800 , 600
window = open_window ( " Mouse Visibility in Spotlight " , window_width , window_height )
spotlight_center = point_at ( window_width / 2 , window_height / 2 )
while not window_close_requested ( window ):
# Process user input events
# Get the current mouse position
mouse_pos = mouse_position ()
# Calculate distance from the mouse to the spotlight center
dx = mouse_pos.x - spotlight_center.x
dy = mouse_pos.y - spotlight_center.y
distance = (dx ** 2 + dy ** 2 ) ** 0.5
# Determine whether to show or hide the mouse
if distance <= spotlight_radius:
show_mouse () # Show the mouse
hide_mouse () # Hide the mouse
# Clear the screen with black color
clear_screen ( color_black ())
# Draw the spotlight as a circle
fill_circle ( color_white () , spotlight_center.x , spotlight_center.y , spotlight_radius )
if __name__ == " __main__ " :