READ THE KEYBOARD

You can share your experience with HMG. Share with some screenshots/project details so that others will also be benefited.

Moderator: Rathinagiri

User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: READ THE KEYBOARD

Post by Czarny_Pijar » Thu Apr 15, 2010 12:00 am

Alex Gustow wrote:Claudio, thanks! Good and very useful I mean!
But... can anybody translate comments etc in this to English (for better understanding and "internationalization")? I think it helps to many guys whose Spanish is "not the best" [like me :) ].
For the translation I use this free website.
http://translate.google.com
Just enter the website address and go.
It is usually good enough. For example, this message was translated from Polish into English completely automatically.

Para la traducción que uso este sitio web gratis.
http://translate.google.com
Sólo tienes que introducir la dirección de Internet y se van.
Por lo general, bastante bueno. Por ejemplo, el mensaje fue traducido del polaco al español de forma totalmente automática.

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 146 times
Contact:

Post by srvet_claudio » Thu Apr 15, 2010 2:22 am

Hi friend Esgici,
esgici wrote:Well, working open-air may be fatiguing but more healthy, it isn't ?
Working with animals is very rewarding, animal nutrition is my true vocation, I have several scientific papers published in national and international journals on ruminant nutrition.
Veterinary medicine has many fields of action.
Animal nutrition is an important field in veterinary medicine, but unfortunately there are very few nutritionists in my country. Most veterinarians are dedicated exclusively to animal diseases.

The programming is just a hobby for me.
esgici wrote:I wish a life always fruitful to you and your wife; God bless you
I also wish that God bless you and your family always

Best regards,
Claudio Soto.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 146 times
Contact:

Post by srvet_claudio » Thu Apr 15, 2010 2:30 am

Czarny_Pijar wrote:For the translation I use this free website.
http://translate.google.com
Hi Czarny_Pijar, I also use the Google translator.
Best regards,
Claudio Soto.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
luisvasquezcl
Posts: 1142
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Has thanked: 14 times
Been thanked: 14 times
Contact:

Post by luisvasquezcl » Thu Apr 15, 2010 3:07 am

Excelente aporte Claudio, y como dice esgici, Gracias doctor.
saludos cordiales,
Luis Vasquez.

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 146 times
Contact:

Post by srvet_claudio » Thu Apr 15, 2010 4:47 am

luisvasquezcl wrote:Excelente aporte Claudio, y como dice esgici, Gracias doctor.
saludos cordiales,
Luis Vasquez.
Gracias Luis,
como siempre eres muy amable.
Un saludo afectuoso,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

PeteWG
Posts: 156
Joined: Sun Mar 21, 2010 5:45 pm
Has thanked: 14 times
Been thanked: 51 times

Post by PeteWG » Thu Apr 15, 2010 11:34 am

srvet_claudio wrote: Hi all,
READ THE KEYBOARD in English (using google).
Best regards,
Claudio Soto
I just saw your very nice contribution! You can't imagine how useful it is.
Thank you very much, Claudio.


best regards,

---
Pete

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 146 times
Contact:

Post by srvet_claudio » Thu Apr 15, 2010 12:59 pm

PeteWG wrote:I just saw your very nice contribution! You can't imagine how useful it is.
Thank you very much, Claudio.
Thanks Pete,
I'm glad that READ THE KEYBOARD is of some use.
Best regards,
Claudio
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

jparada
Posts: 267
Joined: Fri Jan 23, 2009 5:18 pm
Been thanked: 3 times

Post by jparada » Sun Apr 25, 2010 1:27 am

Hi Claudio,

I return to this post, to ask a favor, please take a look at code attached (it's based on your example).

Code: Select all

FUNCTION MAIN( )
	LOCAL frmMain
	
	DEFINE WINDOW frmMain ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 400 ;
		TITLE "Test..." ;
		MAIN 

		If INSTALL_READ_KEYBOARD( ) = .F.
			MsgInfo( "ERROR al instalar READ_KEYBOARD" )
		Endif
		
		_EvalKeyPress( )
			
	END WINDOW

	frmMain.CENTER 
	frmMain.ACTIVATE 
RETURN

PROCEDURE _EvalKeyPress( )
	LOCAL nKeyPress := GET_LAST_VK( )
	
	If ( nKeyPress >= 65 .OR. nKeyPress <= 90 )
		MsgBox( "La tecla oprimida se encuentra en el rango","Test..." )
		// Aqui la idea es activar otra ventana 
	Endif
RETURN
The idea is that when you press the keys 0-9 or a-z or A-Z run, in my case, another window, but in my example is not working well.

Could you please give me some tips to do it right.

I wait your comments please

Thanks

Best Regards
Javier

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 146 times
Contact:

Post by srvet_claudio » Mon Apr 26, 2010 9:24 pm

jparada wrote:The idea is that when you press the keys 0-9 or a-z or A-Z run, in my case, another window, but in my example is not working well.
Hola Javier.
Aca te dejo un ejemplo espero que te sirva.
Saludos,
Claudio Soto

Code: Select all

#include "minigui.ch"

FUNCTION MAIN

foco := ""
   
   DEFINE WINDOW frmMain ;
      AT 0,0 ;
      WIDTH 400 ;
      HEIGHT 400 ;
      TITLE "VENTANA A" ;
      MAIN; 
      ON GOTFOCUS {|| foco := "A"}


      @ 10 , 10 LABEL Label_1 VALUE "PRESIONE: A, B, C, Z o alguna otra tecla" AUTOSIZE
      
* MUY IMPORTANTE *********************************
      INSTALL_READ_KEYBOARD ()                                  // <=== Instala el manejador del teclado, esto solo lo que 
                                                                //      hace es almacenar en una varibale la tecla presionada
                                                                //      y GET_LAST_VK() devuelve el valor de dicha variable.
                                                                		  
	  DEFINE TIMER timer_1 INTERVAL 100 ACTION _EvalKeyPress( ) // <== Esto es lo que llama la funcion que procesa las teclas 
	  
**************************************************      
         
   END WINDOW

   frmMain.CENTER 
   frmMain.ACTIVATE 
RETURN





PROCEDURE _EvalKeyPress( )
   LOCAL nKeyPress := GET_LAST_VK( )
   
   If ( nKeyPress >= 65 .AND. nKeyPress <= 90 )
     
* MUY IMPORTANTE *********************************************      
      PAUSE_READ_VK (.T.) // pausa la lectura del teclado para procesar la tecla presionada
      frmMain.Timer_1.Enabled := .F.
**************************************************************       
       
       DO CASE 
          CASE nKeyPress = 65
               frmMain.setfocus
                   
          CASE nKeyPress = 66
               Ventana2 ()
               
          CASE nKeyPress = 67
               Ventana3 ()
          
          CASE nKeyPress = 90
               MsgBox ("El Foco lo tiene la ventana: "+ foco)
          
          OTHERWISE
               MsgBox( "La tecla oprimida se encuentra en el rango","Test..." )     
       ENDCASE   
       
* MUY IMPORTANTE **************************************************      
      frmMain.Timer_1.Enabled := .T.
      PAUSE_READ_VK (.F.) // restablece la lectura del teclado luego de la pausa
*******************************************************************
  
   Endif
RETURN  
   


Procedure Ventana2

if IsWindowDefined  (Vent2) = .F.
   DEFINE WINDOW Vent2 ;
      AT 0,0 ;
      WIDTH 400 ;
      HEIGHT 400 ;
      TITLE "VENTANA B" ;
      CHILD; 
      ON GOTFOCUS {|| foco := "B"}
      
   END WINDOW
   
* MUY IMPORTANTE **** SIEMPRE ANTES DEL ACTIVE WINDOW*********   
   frmMain.Timer_1.Enabled := .T.
   PAUSE_READ_VK (.F.) // restablece la lectura del teclado
**************************************************************   
   
   vent2.ACTIVATE
   
ELSE
   vent2.setfocus   
ENDIF 

Return


Procedure Ventana3

if IsWindowDefined  (Vent3) = .F.
   DEFINE WINDOW Vent3 ;
      AT 100,100 ;
      WIDTH 400 ;
      HEIGHT 400 ;
      TITLE "VENTANA C" ;
      CHILD;
      ON GOTFOCUS {|| foco := "C"} 
      
   END WINDOW

* MUY IMPORTANTE **** SIEMPRE ANTES DEL ACTIVE WINDOW*********   
   frmMain.Timer_1.Enabled := .T.
   PAUSE_READ_VK (.F.) // restablece la lectura del teclado
**************************************************************   
   
   vent3.ACTIVATE
   
ELSE
   vent3.setfocus   
ENDIF 

Return



*#########################################################################################################################
*   FUNCIONES EN C        
*#########################################################################################################################

#pragma begindump

#include <windows.h>
#include "hbapi.h"

BOOL flag_hhk = FALSE;
BOOL PAUSE_hhk = FALSE;
HHOOK hhk = NULL;
long VK_PRESIONADO = 0;
LONG VK_lParam = 0;


LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode < 0) 
        return CallNextHookEx(hhk, nCode, wParam, lParam);
        
    if (PAUSE_hhk == FALSE)
    {   VK_PRESIONADO = (long) wParam;
        VK_lParam = (LONG) lParam;
    }
    else    
    {   VK_PRESIONADO = 0;
        VK_lParam = 0;
    }   
    
    return CallNextHookEx(hhk, nCode, wParam, lParam);
}


HB_FUNC (GET_STATE_VK_SHIFT)
{
   if (GetKeyState(VK_SHIFT) & 0x8000)
       hb_retl (TRUE); 
   else    
       hb_retl (FALSE);
}


HB_FUNC (GET_STATE_VK_CONTROL)
{
   if (GetKeyState(VK_CONTROL) & 0x8000)
       hb_retl (TRUE); 
   else    
       hb_retl (FALSE);
}


HB_FUNC (GET_STATE_VK_ALT)
{
   if (GetKeyState(VK_MENU) & 0x8000)
       hb_retl (TRUE); 
   else    
       hb_retl (FALSE);
}


HB_FUNC (GET_LAST_VK)
{  if (flag_hhk == TRUE)
       hb_retnl (VK_PRESIONADO);
   else
      hb_retnl (0);    
}


HB_FUNC (GET_LAST_VK_NAME)
{  CHAR cadena [128];

   if (flag_hhk == TRUE)
      {  GetKeyNameText (VK_lParam, (LPTSTR) &cadena, 128);
         hb_retc (cadena);
      }
   else
      hb_retc ("");    
}


HB_FUNC (PAUSE_READ_VK)
{  if (hb_pcount () == 1 && hb_parinfo (1) == HB_IT_LOGICAL)   
   {   if (hb_parl (1) == TRUE) 
       {   VK_PRESIONADO = 0;
           VK_lParam = 0;
       }     
       PAUSE_hhk = hb_parl (1);
   }
}


HB_FUNC (INSTALL_READ_KEYBOARD)
{  if (flag_hhk == FALSE)
   {    hhk = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, (HINSTANCE) NULL, GetCurrentThreadId());
        
        if (hhk == NULL) 
            hb_retl (FALSE);
        else
        {   flag_hhk = TRUE;    
            hb_retl (TRUE);                       
        }   
   }
   else
      hb_retl (TRUE);      
}


HB_FUNC (UNINSTALL_READ_KEYBOARD)
{  if (flag_hhk == TRUE)
   {   if (UnhookWindowsHookEx (hhk) == TRUE)
       {   flag_hhk = FALSE;
           hb_retl (TRUE);           
       }
       else
           hb_retl (FALSE);   
   }
   else
      hb_retl (TRUE);      
}

#pragma enddump

Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

jparada
Posts: 267
Joined: Fri Jan 23, 2009 5:18 pm
Been thanked: 3 times

Post by jparada » Tue Apr 27, 2010 8:22 pm

Hola Claudio,

Muchas Gracias por tu ejemplo y por tu ayuda.

Saludos
Javier

Post Reply