Starten einer Form wenn keine Eingaben ins System erfolgen

  • VB.NET

    Starten einer Form wenn keine Eingaben ins System erfolgen

    Hallo zusammen,

    ich benötige eure Hilfe für ein Problem bei meiner Anwendung. Ich bin selber ziemlich neu in VB und weis nicht wirklich, wie ich das ganze sauber umgesetzt bekomme.

    Das Programm soll folgendens tun:

    Wenn ein Benutzer für x Sekunden ( für meine Test 10s) keine Eingaben tätigt (Tastatur & Maus Systemweit) , soll ein Formular angezeit werden, welches nahezu durchsichtig ist. Bei MouseClick und KeyPress wird die Form ausgebeldent und die Arbeitsstation gesperrt. Ich bekomme es aber irgendwie nicht sauber hin, diese Idle TIme zu erhalten und dann das gewünschte Ereignis auszuführen.



    Es wäre super. wenn ihr mir helfen könntet:


    VB.NET-Quellcode

    1. Option Strict Off
    2. Option Explicit On
    3. Imports VB = Microsoft.VisualBasic
    4. Imports System.Runtime.InteropServices
    5. Friend Class Transparentfrm
    6. Inherits System.Windows.Forms.Form
    7. Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef inputStructure As inputInfo) As Boolean
    8. Private Structure inputInfo
    9. Dim structSize As Int32
    10. Dim tickCount As Int32
    11. End Structure
    12. Private info As inputInfo
    13. Dim firstTick As Long
    14. Dim lastTick As Long
    15. Private Sub transparentfrm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    16. Me.Hide()
    17. GetLastInputInfo(info)
    18. Timer1.Start()
    19. End Sub
    20. 'Sperren der Arbeitsstation bei Verlassen der Anwendung
    21. Private Declare Function LockWorkStation Lib "user32.dll" () As Long
    22. Private Sub frmservice_hide()
    23. LockWorkStation()
    24. Me.Hide()
    25. GetLastInputInfo(info)
    26. Timer1.Start()
    27. End Sub
    28. Private Sub frmservice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
    29. frmservice_hide()
    30. End Sub
    31. Private Sub frmservice_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    32. frmservice_hide()
    33. End Sub
    34. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    35. 'This timer will fire every 1000ms(One Second) or so displaying the last time the user was active.
    36. '
    37. 'The size of the structure for the API call.
    38. info.structSize = Len(info)
    39. '
    40. 'Call the API.
    41. GetLastInputInfo(info)
    42. '
    43. 'Compare the tickcount values to determine if activity has occurred or not.
    44. If firstTick <> info.tickCount Then
    45. Me.Show()
    46. Me.Opacity = 0.1
    47. firstTick = info.tickCount
    48. Timer1.Stop()
    49. End If
    50. End Sub
    51. End Class


    Vielleicht könnt ihr mir helfen.

    Vielen Dank

    Matthias