Hi,

Does anyone want to give me a hand? I gets a small problem in my code. I want to make the mouse pointer is disappeared while pressing 'Alt' key. Otherwise, the pointer should reappear. I use ShowCursor API to do it, but I meet the problem. If I run the program and then I press 'Alt' key, the mouse pointer is disappeared. But, it is not reappeared although I release 'Alt' key.

Please give me a hand.

zawpai

Hi Jx_Man & Estella,

  1. Jx_Man, I have already used and set cursor by showcursor (1) to reappear, but sill can't. It can sense if I press 'Alt' key and release immediately, but If I press that key continuously, it will not be reappeared. Please check for me, I will put my sample code.
  2. Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
  3. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  4. If KeyCode = 17 Then
  5. ' ShowCursor False
  6. ShowCursor 0
  7. End If
  8. End Sub
  9. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  10. If KeyCode = 17 Then
  11. ' ShowCursor True
  12. ShowCursor 1
  13. End If
  14. End Sub

Jx_Man, what do u mean 'check the state'? I don't understand about it.

best regards,
zawpai

hi zawpai...
i was tried your code but when i press alt key nothing happened then i press cntrl key the cursor was disappeared. in my pc alt key = 18 and i tried to reappear but it fail, it work to appear cursor if i press the key continuously. sometimes if i press the alt key to disappear cursor nothing happened and the cursor still appear. then i guest key_down and key_up happened when 1 key pressed (2 event in one key pressed) but key_down do the task first then Key_up works. it's the problem.
i suggest to use other key to reappear the cursor.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode = 17 Then
   ShowCursor 0
 End If
 If KeyCode = 18 Then
   ShowCursor 1
 End If
End Sub

Or

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode = 17 Then
    ShowCursor 0
 End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
 If KeyCode = 18 Then
     ShowCursor 1
 End If
End Sub

Hi Jx_Man,

Sorry for making you confuse. I capture the 'Ctrl' key. You are corrected. The cursor will not be disappeared when you press 'Alt' key. This is my fault.
As I told you, i can do the disappearing and reappearing mouse if I press the 'Ctrl' key and release immediately. But, I can't do the reappearing if i press it continuously.
Could you please try my code again? I don't want to make the reappearing mouse by pressing another key. Do you have another ideas?

best regards,
zawpai

i press the key continuously cause i can reappearing cursor and it works if i lucky.
and i was tried the code again, i got the two result in one press. first when i press 'cntrl' (still pressed) cursor disapper and when i release it back appear again. but it disappear and can't reappearing if i pressed the key for a few second.

Hi Jx_Man,

I also get the same program error. I also don't know how to solve it. Is there another API to do mouse cursor to hide? I also will find better method.


Thanks,
zawpai

This question has already been answered. Start a new discussion instead.