FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Capturar Accion del Usuario
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 12:28 PM

Saludos a todos amigos,,

Tengo un sistema que opera con la BD en la nube.

A cada dialogo le asigno un tiempo determinado para que el usuario ejecute el trabajo (con un timer) , una vez cumplido el tiempo establecido, el formulario se cierra automaticamente.

Es decir, por ejemplo, para ingresar la informacion personal y profesional de un empleado, le determino un tiempo de 10 minutos al dialogo, pasados eso 10 minutos se cierra.

Esto para evitar que un formulario quede abierto en caso de que el usuario se aleje de la pc por mucho tiempo o simplemente se vaya a casa y se le olvide cerrar el dialogo. Hasta alli me funciona muy bien.

El detalle que se me presenta y no he sabido como solventar es cuando el usuario regresa por ejemplo al minuto 9 o al minuto 9 con 50 seg. que quiere decir que regreso antes de que se venciera el tiempo activo del dialogo, pero igualmente se cierra.. es decir, necesito una manera de detectar cuando el usuario ejecute alguna actividad con el formulario, como mover el raton o escribir en un campo y reinicirar el tiempo desde 0

驴Alguien que me de una mano por favor?

"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 12:42 PM

Hola,

SysIdleSecs() pero afecta a todo el sistema

Salu2

Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 01:18 PM

Hola Jos茅,

Entiendo que con el Timer lanzas una funci贸n que S脫LO hace que cerrar el di谩logo (la aplicaci贸n o lo que sea).

Yo modificar铆a lo que hace esa funci贸n de tal manera que controlara el tiempo que ha transcurrido desde un primer momento (al inicio del Timer).
As铆 cuando transcurran 8 minutos podr铆a mostrar un mensaje, pero cuando transcurran 10 cerrar lo que sea.

Si no estoy equivocado un Timer sigue actuando aun cuando se muestre un DIALOG MODAL; que para la soluci贸n que te propongo, en ese DIALOG MODAL estar铆a el aviso de los 8 minutos.

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 01:46 PM
hmpaquito wrote:Hola,

SysIdleSecs() pero afecta a todo el sistema

Salu2


Hola amigo hmpaquito. Podria servirme, el inconveniente que veo es que habria que asignar el mismo tiempo a todos los formularios (si estoy entendiendo bien) , siendo que no todos necesitan la misma cantidad de minutos, de todas maneras voy a investigar sobre esta funcion que me dices, gracias.
"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 01:50 PM
FiveWiDi wrote:Hola Jos茅,

Entiendo que con el Timer lanzas una funci贸n que S脫LO hace que cerrar el di谩logo (la aplicaci贸n o lo que sea).

Yo modificar铆a lo que hace esa funci贸n de tal manera que controlara el tiempo que ha transcurrido desde un primer momento (al inicio del Timer).
As铆 cuando transcurran 8 minutos podr铆a mostrar un mensaje, pero cuando transcurran 10 cerrar lo que sea.

Si no estoy equivocado un Timer sigue actuando aun cuando se muestre un DIALOG MODAL; que para la soluci贸n que te propongo, en ese DIALOG MODAL estar铆a el aviso de los 8 minutos.


Saludos fivwWiDi.
Gracias por responder. Lo que dices ya lo intente, pero sucede lo mismo, el mensaje aparece a los 9 minutos, pero si el usuario regresa a los 9minutos 30 segundos y desea seguir con el formulario, igual se le va a cerrar a los 30 segundos. lo que quiero es que se reinicie el timer nuevamente desde cero para ese formulario cuando se detecte alguna accion.
"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 02:38 PM
Code (fw): Select all Collapse
// \SAMPLES\ALVAREZ.PRG - 23/01/2022.

#Include "FiveWin.ch"  //-> The Best...

FUNCTION Espera_Alvarez()

   LOCAL oDlg, oFld, oFont, aGrad
   LOCAL aBitmaps := { "..\bitmaps\alphabmp\facebook.bmp", ;
                       "..\bitmaps\alphabmp\windows.bmp" }

   LOCAL nTempo_espera, cNome_funcao, lTimercontinua

   // -> 1 hora tem 3600 segundos.
   nTempo_espera := 15  // segundos.

   cNome_funcao := "LOGOFF()"   

   lTimercontinua := .F.

   aGrad := { { 0.30, CLR_WHITE, CLR_HBLUE },{ 0.50, CLR_HBLUE, CLR_WHITE } }

   DEFINE FONT oFont   NAME "Ms Sans Serif" SIZE 00, -14 BOLD
                      
   DEFINE DIALOG oDlg TITLE "- TFolderex - Testing -" SIZE 350, 350          ;
      PIXEL TRUEPIXEL RESIZABLE GRADIENT aGrad
     
   @ 1, 0 FOLDEREX oFld PIXEL ADJUST OF oDlg ;
      PROMPT "Prenotazioni", "Pagamenti"     ;
      BITMAPS aBitmaps                       ;
      TAB HEIGHT 26 OPTION 1 ROUND 5 FONT oFont COLOR CLR_HGREEN TOP

   oFld:aEnable = { .T., .T., .F. }

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT( oFld:Resize(), TINATIVO():NEW( nTempo_espera, cNome_funcao,   ;
                              lTimerContinua ) )

RETURN NIL

// tinativo.prg - By William Adami
// exemplo do uso da classe Tinativo
// Apos um tempo de inatividade do mouse
// e do teclado chama uma funcao qualquer.

//#include "fivewin.ch"

// STATIC oWnd

//************

/*
FUNCTION Main()

   LOCAL nTempo_espera, cNome_funcao, lTimercontinua

   // Tempo a ser esperado ate chamar a funcao
   // -> 1 hora tem 3600 segundos.
   nTempo_espera := 10  // segundos. 

   // nome da funcao a ser chamada quando
   // chegar no tempo de espera
   cNome_funcao := "LOGOFF()"   
   // se apos executar a funcao , continua
   // monitorando a inatividade do mouse e teclado.
   lTimercontinua := .F.

   define window oWnd title "Teste de teclado e mouse"

   activate window oWnd ;
      ON INIT tinativo():new( nTempo_espera, cNome_funcao, lTimerContinua )

RETURN NIL
*/

FUNCTION LOGOFF()

   // msgalert( "AQUI ENTRA SUA FUNCAO DE LOGOFF !", "AVISO" )

   IF MsgYesNo( OemToAnsi( "ATEN鈧嘜 USU碌RIO:                       " )+CRLF+ ;
                OemToAnsi( "PROTEJA OS BANCOS DE DADOS DO PROGRAMA." )+CRLF+ ;
                OemToAnsi( "SE N脟O ESTIVER USANDO O ALVAREZ.EXE,   " )+CRLF+ ;
                OemToAnsi( "DESLIGUE-O PARA N脟O CORRER RISCOS.     " )+CRLF+ ;
                OemToAnsi( "POSSO DESLIGAR O PROGRAMA? <S> ou <N>??" ),      ;
                OemToAnsi( "AVISO PARA DESLIGAR O ALVAREZ.EXE...   " ) )

      HB_GCALL( .T. )

      CLEAR MEMORY

      PostQuitMessage( 0 )

      QUIT

   ENDIF

RETURN NIL

//   tinativo.prg -> By William Adami

// #include "fivewin.ch"

CLASS TINATIVO

   DATA nTimeInpAntes
   DATA nTimeInpDepois
   DATA cTimeAtu
   DATA nTempo
   DATA oTimerTime
   DATA cFunc
   DATA lContinuar

   METHOD NEW( nTime, cFuncao, lContinua )  CONSTRUCTOR

   METHOD ver_tempo()

ENDCLASS

METHOD new( ntime, cFuncao, lContinua ) CLASS TINATIVO

   ::cfunc := cfuncao
   ::ntempo := ntime
   ::lContinuar := lContinua
   ::oTimerTime := TTimer():New( 1000, { || ::VER_TEMPO() } )
   ::oTimerTime:Activate()
   ::cTimeAtu := time()
   ::nTimeInpAntes := getInputState()    // 0 = erro

RETURN self

METHOD VER_TEMPO CLASS TINATIVO

   LOCAL AUX

   ::nTimeInpDepois := getInputState()

   IF ( ::nTimeInpDepois - ::nTimeInpAntes ) > 0

      ::nTimeInpAntes := getInputState()

      ::cTimeAtu := time()

   ENDIF


   IF ( CONVTIME( time() ) - CONVTIME( ::cTimeAtu ) ) > ::ntempo

      ::oTimerTime:DeActivate()

      aux := ::cfunc
   
      // aqui executa a funcao

      &aux

      if ::lContinuar

         ::oTimerTime:Activate()
         ::cTimeAtu := time()

      ENDIF


   ENDIF

RETURN NIL

FUNCTION CONVTIME( ZZ )

   LOCAL Z

   Z := ( VAL( LEFT(ZZ,2 ) ) * 360 ) + ( VAL( SUBSTR(ZZ,4,2 ) ) * 60 ) + ;
          VAL( RIGHT( ZZ,2 ) )

RETURN Z

//*----------------------------------------------------------------------
#pragma BEGINDUMP
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include "windows.h"
#include "hbapi.h"
HB_FUNC( GETINPUTSTATE )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
hb_retni(0);
}
hb_retni(lpi.dwTime);
}
#pragma ENDDUMP

// fin / end



Regards, saludos.
Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: Capturar Accion del Usuario
Posted: Wed Feb 23, 2022 03:13 PM
karinha wrote:
Code (fw): Select all Collapse
// \SAMPLES\ALVAREZ.PRG - 23/01/2022.

#Include "FiveWin.ch" 聽//-> The Best...

FUNCTION Espera_Alvarez()

聽 聽LOCAL oDlg, oFld, oFont, aGrad
聽 聽LOCAL aBitmaps := { "..\bitmaps\alphabmp\facebook.bmp", ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽"..\bitmaps\alphabmp\windows.bmp" }

聽 聽LOCAL nTempo_espera, cNome_funcao, lTimercontinua

聽 聽// -> 1 hora tem 3600 segundos.
聽 聽nTempo_espera := 15 聽// segundos.

聽 聽cNome_funcao := "LOGOFF()" 聽 

聽 聽lTimercontinua := .F.

聽 聽aGrad := { { 0.30, CLR_WHITE, CLR_HBLUE },{ 0.50, CLR_HBLUE, CLR_WHITE } }

聽 聽DEFINE FONT oFont 聽 NAME "Ms Sans Serif" SIZE 00, -14 BOLD
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 
聽 聽DEFINE DIALOG oDlg TITLE "- TFolderex - Testing -" SIZE 350, 350 聽 聽 聽 聽 聽;
聽 聽 聽 PIXEL TRUEPIXEL RESIZABLE GRADIENT aGrad
聽 聽 聽
聽 聽@ 1, 0 FOLDEREX oFld PIXEL ADJUST OF oDlg ;
聽 聽 聽 PROMPT "Prenotazioni", "Pagamenti" 聽 聽 ;
聽 聽 聽 BITMAPS aBitmaps 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ;
聽 聽 聽 TAB HEIGHT 26 OPTION 1 ROUND 5 FONT oFont COLOR CLR_HGREEN TOP

聽 聽oFld:aEnable = { .T., .T., .F. }

聽 聽ACTIVATE DIALOG oDlg CENTERED ;
聽 聽 聽 ON INIT( oFld:Resize(), TINATIVO():NEW( nTempo_espera, cNome_funcao, 聽 ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 lTimerContinua ) )

RETURN NIL

// tinativo.prg - By William Adami
// exemplo do uso da classe Tinativo
// Apos um tempo de inatividade do mouse
// e do teclado chama uma funcao qualquer.

//#include "fivewin.ch"

// STATIC oWnd

//************

/*
FUNCTION Main()

聽 聽LOCAL nTempo_espera, cNome_funcao, lTimercontinua

聽 聽// Tempo a ser esperado ate chamar a funcao
聽 聽// -> 1 hora tem 3600 segundos.
聽 聽nTempo_espera := 10 聽// segundos. 

聽 聽// nome da funcao a ser chamada quando
聽 聽// chegar no tempo de espera
聽 聽cNome_funcao := "LOGOFF()" 聽 
聽 聽// se apos executar a funcao , continua
聽 聽// monitorando a inatividade do mouse e teclado.
聽 聽lTimercontinua := .F.

聽 聽define window oWnd title "Teste de teclado e mouse"

聽 聽activate window oWnd ;
聽 聽 聽 ON INIT tinativo():new( nTempo_espera, cNome_funcao, lTimerContinua )

RETURN NIL
*/

FUNCTION LOGOFF()

聽 聽// msgalert( "AQUI ENTRA SUA FUNCAO DE LOGOFF !", "AVISO" )

聽 聽IF MsgYesNo( OemToAnsi( "ATEN鈧嘜 USU碌RIO: 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 " )+CRLF+ ;
聽 聽 聽 聽 聽 聽 聽 聽 OemToAnsi( "PROTEJA OS BANCOS DE DADOS DO PROGRAMA." )+CRLF+ ;
聽 聽 聽 聽 聽 聽 聽 聽 OemToAnsi( "SE N脟O ESTIVER USANDO O ALVAREZ.EXE, 聽 " )+CRLF+ ;
聽 聽 聽 聽 聽 聽 聽 聽 OemToAnsi( "DESLIGUE-O PARA N脟O CORRER RISCOS. 聽 聽 " )+CRLF+ ;
聽 聽 聽 聽 聽 聽 聽 聽 OemToAnsi( "POSSO DESLIGAR O PROGRAMA? <S> ou <N>??" ), 聽 聽 聽;
聽 聽 聽 聽 聽 聽 聽 聽 OemToAnsi( "AVISO PARA DESLIGAR O ALVAREZ.EXE... 聽 " ) )

聽 聽 聽 HB_GCALL( .T. )

聽 聽 聽 CLEAR MEMORY

聽 聽 聽 PostQuitMessage( 0 )

聽 聽 聽 QUIT

聽 聽ENDIF

RETURN NIL

// 聽 tinativo.prg -> By William Adami

// #include "fivewin.ch"

CLASS TINATIVO

聽 聽DATA nTimeInpAntes
聽 聽DATA nTimeInpDepois
聽 聽DATA cTimeAtu
聽 聽DATA nTempo
聽 聽DATA oTimerTime
聽 聽DATA cFunc
聽 聽DATA lContinuar

聽 聽METHOD NEW( nTime, cFuncao, lContinua ) 聽CONSTRUCTOR

聽 聽METHOD ver_tempo()

ENDCLASS

METHOD new( ntime, cFuncao, lContinua ) CLASS TINATIVO

聽 聽::cfunc := cfuncao
聽 聽::ntempo := ntime
聽 聽::lContinuar := lContinua
聽 聽::oTimerTime := TTimer():New( 1000, { || ::VER_TEMPO() } )
聽 聽::oTimerTime:Activate()
聽 聽::cTimeAtu := time()
聽 聽::nTimeInpAntes := getInputState() 聽 聽// 0 = erro

RETURN self

METHOD VER_TEMPO CLASS TINATIVO

聽 聽LOCAL AUX

聽 聽::nTimeInpDepois := getInputState()

聽 聽IF ( ::nTimeInpDepois - ::nTimeInpAntes ) > 0

聽 聽 聽 ::nTimeInpAntes := getInputState()

聽 聽 聽 ::cTimeAtu := time()

聽 聽ENDIF


聽 聽IF ( CONVTIME( time() ) - CONVTIME( ::cTimeAtu ) ) > ::ntempo

聽 聽 聽 ::oTimerTime:DeActivate()

聽 聽 聽 aux := ::cfunc
聽 聽
聽 聽 聽 // aqui executa a funcao

聽 聽 聽 &aux

聽 聽 聽 if ::lContinuar

聽 聽 聽 聽 聽::oTimerTime:Activate()
聽 聽 聽 聽 聽::cTimeAtu := time()

聽 聽 聽 ENDIF


聽 聽ENDIF

RETURN NIL

FUNCTION CONVTIME( ZZ )

聽 聽LOCAL Z

聽 聽Z := ( VAL( LEFT(ZZ,2 ) ) * 360 ) + ( VAL( SUBSTR(ZZ,4,2 ) ) * 60 ) + ;
聽 聽 聽 聽 聽 VAL( RIGHT( ZZ,2 ) )

RETURN Z

//*----------------------------------------------------------------------
#pragma BEGINDUMP
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include "windows.h"
#include "hbapi.h"
HB_FUNC( GETINPUTSTATE )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
hb_retni(0);
}
hb_retni(lpi.dwTime);
}
#pragma ENDDUMP

// fin / end



Regards, saludos.



Gracias Joao.
Voy a probar tu ejemplo y te comento como me va.

Un Abrazo.
"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 537
Joined: Mon Jan 16, 2006 03:42 PM
Re: Capturar Accion del Usuario
Posted: Thu Feb 24, 2022 12:13 PM

Continue the discussion