GET KEYPRESS OUTSIDE on key events

Friend , many times we need to detect key down or key press outside KeyDown event
 i find the solution to do it.

First Add The Following code Outside Any SUB and inside CLASS .


Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short

Now Place Some Variables Bellow That

  Public Const VK_A = &H41 ' A
    Public Const VK_Z = &H54 ' Z
    Public Const VK_LSHIFT = 37 ' &HA0
    Public Const VK_RSHIFT = 39 ' &HA1
    Public Const VK_LKCONTROL = &HA2
    Public Const VK_RKCONTROL = &HA3
    Public Const VK_RIGHT = &H27
    Public Const VK_LEFT = &H25
    Public Const VK_UP = &H26
    Public Const VK_DOWN = &H28
    Public Const VK_SPACE = 32   '&H20
    Public Const VK_ESC = &H1B
It looks something like this :
Now Detecting The KeyPress :-
 The Best Way To Do So Is Timer ; Place following code inside Timer_Tick Event

If GetAsyncKeyState(VarKeyName) Then
''Action to be done 
End If

An Example

If GetAsyncKeyState(VK_RIGHT) Then
Msgbox("It Works")
End If
it looks something like

 

Note :- Make Sure That TIMER in which u Place code is Enabled TRUE else it Wont Work .


2 comments:

  1. nice ! really helps

    ReplyDelete
  2. I WAS TIRED OF SURFING
    FINALLY I FOUND IT HERE

    I GIVE U 7 STARS

    ReplyDelete

Note: only a member of this blog may post a comment.

Translate