Results 1 to 3 of 3

Thread: *HELP* inactivity in the application

  1. #1
    Rcarvalho
    Guest

    Unhappy *HELP* inactivity in the application

    Hello!

    Can somenone please help me?
    I need to know how I can know how much time an apllication
    is inactive (without any mousemove or keypress), without using any timer control, only API.

    can you help me, please?
    it's urgent!!!

    thanks in advance!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    This should give you a start
    VB Code:
    1. Public Const DT_CENTER = &H1
    2. Public Const DT_WORDBREAK = &H10
    3. Public Type RECT
    4.     Left As Long
    5.     Top As Long
    6.     Right As Long
    7.     Bottom As Long
    8. End Type
    9. Public Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
    10. Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    11. Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    12. Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    13. Public Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    14. Public Cnt As Long, sSave As String, sOld As String, Ret As String
    15. Public Tel As Long
    16. Public Function GetPressedKey() As String
    17.     For Cnt = 32 To 128
    18.         'Get the keystate of a specified key
    19.         If GetAsyncKeyState(Cnt) <> 0 Then
    20.             GetPressedKey = Chr$(Cnt)
    21.             Exit For
    22.         End If
    23.     Next Cnt
    24. End Function
    25. Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    26.     Ret = GetPressedKey
    27.     If Ret <> sOld Then
    28.         sOld = Ret
    29.         sSave = sSave + sOld
    30.     End If
    31. End Sub
    32.  
    33. 'In a form
    34. Private Sub Form_Load()
    35.     'KPD-Team 1999
    36.     'URL: [url]http://www.allapi.net/[/url]
    37.     'E-Mail: [email][email protected][/email]
    38.     Me.Caption = "Key Spy"
    39.     'Create an API-timer
    40.     SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
    41. End Sub
    42. Private Sub Form_Paint()
    43.     Dim R As RECT
    44.     Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
    45.     'Clear the form
    46.     Me.Cls
    47.     'API uses pixels
    48.     Me.ScaleMode = vbPixels
    49.     'Set the rectangle's values
    50.     SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    51.     'Draw the text on the form
    52.     DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
    53. End Sub
    54. Private Sub Form_Resize()
    55.     Form_Paint
    56. End Sub
    57. Private Sub Form_Unload(Cancel As Integer)
    58.     'Kill our API-timer
    59.     KillTimer Me.hwnd, 0
    60.     'Show all the typed keys
    61.     MsgBox sSave
    62. End Sub

  3. #3
    Rcarvalho
    Guest

    Exclamation

    Sorry!

    that Kind of helped me, but it only works if i use two applications!
    right?

    i need to determine when only one is inactive!
    get it?

    Thanks anyway!

    I'm going to keep on trying anyeay!
    If someone can help me please do!

    I'v etried manyways bu still no sucess and time is running short

    best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width