What do you mean by "is click otherwise". Anyways, Duoas is correct, this is a very bad idea. I for one have never played a windowed video game that wont let my cursor go out of the window.
It is not your right to dictate to the user how to use his system. Your program should only operate within the window given it. Programs that do otherwise are quickly uninstalled by users.
If it is a problem that you need to have the cursor in the window when you press a key, just do something like ignore it or complain to the user that the mouse cursor is not on a selectable item, etc.
It sound like you are drawing a cursor on your window at a position where you think the mouse cursor is and it is this code that is not working correctly.