how to select polygon under cursor (without clicking)

Hi, i'm trying to write a script where i hover my mouse over editpoly object in subobject level 0, run script and it gets the multisub material ID of that polygon. My approach is to select object, and while my cursor is above desired polygon to run the script, which in turn:
enters polygon mode
selects said polygon
retrieves id
exits polygon subobject mode.

My problem is to select polygon under the cursor by script. Can somebody please help me?

Or if there is some better approach to do this, please help me.

Thanx,
Jan