How to prevent tilemap from filling entire screen, and detect mouse entering and exiting tile

Godot Version

Godot v4.2.1.stable.official

Question

I am attempting to make a board game like scrabble. I am using a tilemap for the game board which is a child of a control node for board UI functions. I am attempting to highlight the tile the mouse is over. There is not a convenient way to detect the mouse entering and leaving a tile, so I found a way to do it, but it’s a little hacky. The board does not take up the entire screen, and this caused cells outside the board to highlight, such as highlighting non-existent cells over other UI features. Code below. I enforced bounds on the mouse input check, but ideally the control node is limited to just over the board so it is not constantly monitoring mouse input when the mouse is elsewhere. Is there a way to limit the size of the control node, or the size of the tilemap? Or is there just a cleaner way of detecting when the mouse is entering or exiting a tile? I have attached a screenshot of the issue with highlighting.

Function in the control node that calls the board tilemap, where lower and upper bound are the top left and bottom right corners of the game board.

# highlight the tile the mouse is over
func _input(event: InputEvent) -> void:
	var mouse_motion := event is InputEventMouseMotion
	var local_mouse_position = get_local_mouse_position()
	if LOWER_BOUND <= local_mouse_position and UPPER_BOUND >= local_mouse_position:
		if mouse_motion:
			board_tile_map.highlight_cell(local_mouse_position)

Function in the tilemap:

func highlight_cell(local_mouse_pos: Vector2i) -> void:
	if curr_highlighted_tile:
		erase_cell(SELECTOR_LAYER, curr_highlighted_tile)
	
	curr_highlighted_tile = local_to_map(local_mouse_pos)
	set_cell(SELECTOR_LAYER, curr_highlighted_tile, SOURCE_ID, HIGHLIGHT_TILE_COORDS)

Screenshot 2024-05-10 at 12.03.07 AM

edited to fix wording

this code should already block the input if it’s outside the camera, if you want it to only be able to input inside the board area, then you will need to set it up so that it only take input if it’s inside the board size range

How would I set it up that way? New-ish to Godot so apologies if this should be obvious.

func _input(event: InputEvent) -> void:
	var mouse_motion := event is InputEventMouseMotion
	var local_mouse_position = get_local_mouse_position()
	var pos_clicked= Vector2(local_to_map(local_mouse_position))
	if LOWER_BOUND <= local_mouse_position and UPPER_BOUND >= local_mouse_position:
		if mouse_motion and pos_clicked>=Vector2.ZERO and pos_clicked<Vector2(board_col,board_row) :
			board_tile_map.highlight_cell(local_mouse_position)

the board_col and board_row is the size of your board