mouse locke for value specific

Hello, I created a C ++ program, which I linked to a game.
I gave an address on which I can give actions, for example mouse event, it works.
My goal is to insist that when this value is correct the mouse will stay on this object even if I am moving where it does.
until it passes behind a wall where the changed value becomes 0.