Page 2 of 4
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 5:41 pm
by srvet_claudio
Thanks Alex.
Alex Gustow wrote: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"
You are right.
My excuses, my English is very poor.
Best regards,
Claudio Soto
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 6:57 pm
by esgici
Alex Gustow wrote:...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
].
I agree heartily with Alex
Saludos, regards
--
Esgici
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 7:15 pm
by srvet_claudio
Alex Gustow wrote: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"
Hi all,
READ THE KEYBOARD in English (using google).
Best regards,
Claudio Soto
Code: Select all
****************************************************************************
* PROGRAMA: READ THE KEYBOARD
* LENGUAJE: HARBOUR-MINIGUI 3.0.29
* FECHA: 13 ABRIL 2010
* AUTOR: CLAUDIO SOTO
* PAIS: URUGUAY
* E-MAIL: srvet@adinet.com.uy
****************************************************************************
***************************************************************************************************
* DESCRIPTION
*
* Read keyboard input entries and returns information about the key pressed.
* These functions intercept keyboard messages from the system will send the application
* (WM_KEYUP and WM_KEYDOWN) and stores information about the virtual key generated.
*
***************************************************************************************************
***************************************************************************************************
* SYNTAX:
*
* INSTALL_READ_KEYBOARD () // Install the "driver" that reads the keyboard (returns. T. if successful)
* UNINSTALL_READ_KEYBOARD () // Uninstall the "driver" that reads the keyboard (returns. T. if successful)
*
* GET_LAST_VK() // Returns the virtual value (VK Code) of the key pressed
* GET_LAST_VK_NAME() // Returns the name of the virtual key press
*
* GET_STATE_VK_SHIFT () // Returns. T. if SHIFT key is pressed
* GET_STATE_VK_CONTROL () // Returns. T. if CONTROL key is pressed
* GET_STATE_VK_ALT () // Returns. T. if ALT key is pressed
*
* PAUSE_READ_VK (.T.) // Pause reading keyboard in order to process the key pressed
* PAUSE_READ_VK (.F.) // Restore keyboard reading after the pause
*
*******************************************************************************************************
* Virtual values (VK Code) of the different keys can be found in the file
* C:\hmg.3.0.29\MinGW\include\winuser.h
*
* They begin with the prefix # define VK_
* For example, # define VK_SHIFT 16
*******************************************************************************************************
#include "minigui.ch"
Function Main
SET LANGUAGE TO ENGLISH
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 600 ;
TITLE 'READ THE KEYBOARD' ;
MAIN
@ 10 , 10 LABEL Label_1 AUTOSIZE BOLD FONTCOLOR RED
@ 40 , 10 LABEL Label_2 AUTOSIZE BOLD FONTCOLOR RED
@ 80 , 10 LABEL Label_3 AUTOSIZE BOLD FONTCOLOR BLUE
@ 120 , 10 LABEL Label_4 AUTOSIZE BOLD FONTCOLOR BLUE
@ 160 , 10 LABEL Label_5 AUTOSIZE BOLD FONTCOLOR BLUE
@ 200 , 10 LABEL Label_6 AUTOSIZE BOLD FONTCOLOR BROWN
@ 240 , 10 LABEL Label_7 AUTOSIZE BOLD FONTCOLOR BROWN
@ 280 , 10 LABEL Label_8 AUTOSIZE BOLD FONTCOLOR BROWN
@ 420 , 10 LABEL Label_9 AUTOSIZE BOLD
@ 380 , 10 LABEL Label_10 VALUE "Press SHIFT + A open Dialog Box" AUTOSIZE BOLD
@ 450 , 10 EDITBOX EditBox_1 WIDTH 200 HEIGHT 100 VALUE "Write"
IF INSTALL_READ_KEYBOARD () = .F.
MsgInfo ("ERROR when installing READ_KEYBOARD")
ELSE
DEFINE TIMER timer_1 OF Form_1 INTERVAL 100 action Show_Key ()
ENDIF
// IF UNINSTALL_READ_KEYBOARD () = .F.
// MsgInfo ("ERROR when uninstalling READ_KEYBOARD")
// ELSE
// Form_1.Timer_1.Release
// ENDIF
END WINDOW
Form_1.Center
Form_1.Activate
Return
Procedure Show_Key
Form_1.Label_1.Value := "VK Code: " + str (GET_LAST_VK())
Form_1.Label_2.Value := "VK Name: " + GET_LAST_VK_NAME()
Form_1.Label_3.Value := "Pressed SHIFT : " + IF (GET_STATE_VK_SHIFT()=.T.,"Yes","No")
Form_1.Label_4.Value := "Pressed CONTROL: " + IF (GET_STATE_VK_CONTROL()=.T.,"Yes","No")
Form_1.Label_5.Value := "Pressed ALT: " + IF (GET_STATE_VK_ALT()=.T.,"Yes","No")
Form_1.Label_6.Value := "CAPS LOCK: " + IF (IsCapsLockActive() =.T.,"On","Off") // HMG function
Form_1.Label_7.Value := "NUM LOCK: " + IF (IsNumLockActive() =.T.,"On","Off") // HMG function
Form_1.Label_8.Value := "INSERT: " + IF (IsInsertActive() =.T.,"On","Off") // HMG function
IF (GET_STATE_VK_SHIFT()=.T. .OR. IsCapsLockActive() =.T.) .AND. GET_LAST_VK() <> 0
Form_1.Label_9.Value := "Writing in CAPS"
ELSE
Form_1.Label_9.Value := "Writing in MINISCULE"
ENDIF
IF GET_LAST_VK() = 65 .AND. GET_STATE_VK_SHIFT()=.T. // VK code A = 65
PAUSE_READ_VK (.T.) // Pause reading keyboard in order to process the key pressed
Form_1.Timer_1.Enabled := .F.
Msginfo ("Process the action of the SHIFT + A")
Form_1.Timer_1.Enabled := .T.
PAUSE_READ_VK (.F.) // Restore keyboard reading after the pause
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
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 7:23 pm
by esgici
Thanks Dr.
By the way, does "srvt" means "speedy"
Saludos cordiales.
--
Esgici
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 8:41 pm
by jparada
Hola Claudio,
Muchas Gracias por esta implementación.
Realmente un gran esfuerzo de tu parte.
Saludos
Javier
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 8:44 pm
by srvet_claudio
Hi Esgici,
esgici wrote:By the way, does "srvt" means "speedy"
Yes of course,
S = super
R = rápido (fast)
VET = Veterinary
No, it's a joke
srvet = Soto & Reinoso veterinary.
Valeria Reinoso is my wife.
srvet@adinet.com.uy is our professional e-mail
Best regards,
Claudio
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 8:50 pm
by srvet_claudio
jparada wrote:Hola Claudio,
Muchas Gracias por esta implementación.
Realmente un gran esfuerzo de tu parte.
Saludos
Javier
Hola Javier,
Es un placer poder colaborar, programar es mi hobby.
Saludos,
Claudio Soto
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 9:07 pm
by esgici
Hola Dr.
Your joke is good as your programs
Your veterinary clinic is family-size, very well.
By the way, in my language we have a word most similar your nickname :
servet : its mean is
fortune,
richness
Saludos
--
Esgici
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 10:12 pm
by srvet_claudio
Hi friend Esgici,
thanks for your always kind words.
In reality we not have a veterinary clinic.
We are ranchers (breeding cattle and sheep) and we work as consultants in animal production.
In Uruguay, the livestock is a very important activity for the country economy.
Best regards,
Claudio.
Re: READ THE KEYBOARD
Posted: Wed Apr 14, 2010 10:32 pm
by esgici
Hola Amigo Claudio
Well, working open-air may be fatiguing but more healthy, it isn't ?
I wish a life always fruitful to you and your wife; God bless you
Saludos
--
Esgici