Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Rudy21 en 17 Octubre 2008, 21:24 pm



Título: Saber Si Pc Está Inactiva
Publicado por: Rudy21 en 17 Octubre 2008, 21:24 pm
Pues Necesito saber eso


si una pc está inactiva por ejemplo apagarla

c me ocurrio esto:

inicia TIMER, registra la posicion de el mouse en 2 textbox X & Y

si al trascurrir el tiempo la posision del mouse es igual a la de x & y

(igual a inactividad) apagar

en caso de cambiar el valor de el textbox o de presionar na tecla

se renicia el timer

alguna idea?

gracias


Título: Re: Saber Si Pc Está Inactiva
Publicado por: cobein en 17 Octubre 2008, 21:28 pm
podes usar GetLastInputInfo


Título: Re: Saber Si Pc Está Inactiva
Publicado por: Karcrack en 17 Octubre 2008, 22:16 pm
Bueno, he hecho un ejemplo de uso, lo reconozco, me aburria mucho :xD:


Has de agregar un Timer con intervalo 100, y cuando lleves 5 segundos inactivo se mostrara un msgbox...

Código
  1. Option Explicit
  2.  
  3. Private Type PLASTINPUTINFO
  4.    cbSize      As Long
  5.    dwTime      As Long
  6. End Type
  7.  
  8. Private Declare Function GetTickCount Lib "kernel32" () As Long
  9. Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef plii As PLASTINPUTINFO) As Long
  10.  
  11. '---------------------------------------------------------------------------------------
  12. ' Procedure : GetIdleMs
  13. ' Author    : Karcrack
  14. ' Date      : 17/10/2008
  15. ' Purpose   : Obtiene los Ms desde el ultimo movimiento del usuario.
  16. '---------------------------------------------------------------------------------------
  17. '
  18. Public Function GetIdleMs() As Double
  19.    Dim PlastII         As PLASTINPUTINFO
  20.  
  21.    PlastII.cbSize = Len(PlastII)
  22.  
  23.    Call GetLastInputInfo(PlastII)
  24.  
  25.    GetIdleMs = GetTickCount - PlastII.dwTime
  26. End Function
  27.  
  28. '---------------------------------------------------------------------------------------
  29. ' Procedure : Timer_Timer
  30. ' Interval  : 100 ms
  31. '---------------------------------------------------------------------------------------
  32. '
  33. Private Sub Timer_Timer()
  34.    If GetIdleMs > 5000 Then
  35.        MsgBox "Llevas 5 segundos inactivo."
  36.    End If
  37. End Sub

Saludos :D