Setting mouse position

Is there any way to set the position of the mouse cursor or to keep it inside the window? I’m trying to make it so that the cursor will always stay in the right half of the screen, so that if the player tries to move the mouse onto the left side it will just stop at the dividing line. Making the cursor hidden and drawing my own doesn’t help much if the mouse can leave the window.

This will keep the mouse on the right side of the window. Just add more conditions to keep it in the top, right, and bottom of the window.

mouse_id = 0
if base.mouseWatcherNode.hasMouse():
    mouse_x = base.mouseWatcherNode.getMouseX()
    mouse_y = base.mouseWatcherNode.getMouseY()
    win_middle_x = base.win.getXSize() / 2
    if mouse_x < win_middle_x:
        mouse_x = win_middle_x
    base.win.movePointer(mouse_id, mouse_x, mouse_y)

Those functions are probably tucked away someplace different if you are using Panda 1.7, check the online reference.