Envio Teclas a un Get

Mike Serra
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Envio Teclas a un Get

Post by Mike Serra »

Buenos días foro, me gustaria saber si alguien ha tenido que hacer algo similar a esto. Tengo un dialogo, en él, un get y unos botones simulando un teclado numérico. Lógicamente el get responde perfectamente a las pulsaciones del teclado, pero me gustaría que cuando pulsara en los botones de la pantalla, respondiera igual de bien, pero no es así. Estoy enviando contenido (1,2,3,4,5 . . .) cuando presiono los botones de varias manera, pero ninguna me funciona. He usado,

SendMessage(oGet,WM_CHAR. . .)
SendMessage(oGet,WM_KEYDOWN...)
oGET:PostMsg( . . . )


¿Alguien me puede ayudar?

Espero haberme explicado bien.

Un Saludo,
User avatar
Antonio Linares
Site Admin
Posts: 42450
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 20 times
Been thanked: 58 times
Contact:

Re: Envio Teclas a un Get

Post by Antonio Linares »

Mike,

Aqui tienes la función SendKey() basada en la función SendInput() del API de Windows:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
y que incluimos en FWH 11.10

Code: Select all | Expand

HB_FUNC( SENDKEY )
{
     INPUT input;

   input.type           = INPUT_KEYBOARD;
   input.ki.wVk         = hb_parnl( 1 );
   input.ki.wScan       = 0;
   input.ki.dwFlags     = 0;
   input.ki.time        = 0;
   input.ki.dwExtraInfo = 0;
     
   hb_retnl( SendInput( 1, &input, sizeof( input ) ) );
}


Ojo que esta función manda la tecla a la aplicación, luego la procesará el control que tenga foco
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Re: Envio Teclas a un Get

Post by anserkk »

Did you try

Code: Select all | Expand

@03,01 BUTTON oBtn_A ACTION PostMessage( oGet1:hWnd, WM_CHAR, 65, 0 )  // Puts A on oGet1
@04,01 BUTTON oBtn_B ACTION PostMessage( oGet2:hWnd, WM_CHAR, 66, 0 )  // Puts B on oGet2
 


Sample Code

Code: Select all | Expand

#include "FiveWin.ch"
//-----------------------//
Function Main()

    Local oDlg,oGet,cVar:=Space(30),oBtn1,oBtn2,oBtn3,oBtn4

    DEFINE DIALOG oDlg TITLE "Test"
   
        @01,01 GET oGet VAR cVar SIZE 100,12    

        @03,01 BUTTON oBtn1 PROMPT "1" SIZE 10,10 ACTION (PostMessage( oGet:hWnd, WM_CHAR, 49, 0 ),oGet:Refresh())
        @03,03 BUTTON oBtn2 PROMPT "2" SIZE 10,10 ACTION (PostMessage( oGet:hWnd, WM_CHAR, 50, 0 ),oGet:Refresh())
        @03,05 BUTTON oBtn3 PROMPT "3" SIZE 10,10 ACTION (PostMessage( oGet:hWnd, WM_CHAR, 51, 0 ),oGet:Refresh())
        @03,07 BUTTON oBtn4 PROMPT "4" SIZE 10,10 ACTION (PostMessage( oGet:hWnd, WM_CHAR, 52, 0 ),oGet:Refresh())        

    ACTIVATE DIALOG oDlg
     
Return nil

Regards

Anser
Mike Serra
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Post by Mike Serra »

Como siempre, gracias por contestar.


1) Antonio, no he podido probarlo, ya que el proyecto está en FWH901 y bcc55. He insertado el siguiente codigo en mi prg

Code: Select all | Expand


#pragma BEGINDUMP

#include "winuser.h"
#include "windows.h"

HB_FUNC( SENDKEY )
{
     INPUT input;

   input.type           = INPUT_KEYBOARD;
   input.ki.wVk         = hb_parnl( 1 );
   input.ki.wScan       = 0;
   input.ki.dwFlags     = 0;
   input.ki.time        = 0;
   input.ki.dwExtraInfo = 0;
     
   hb_retnl( SendInput( 1, &input, sizeof( input ) ) );
}

#pragma ENDDUMP

 


Pero me da una serie de errores en winuser.h .... Si no la incluyo, me da una serie de errores (no encuentra la etiqueta IMPUT)

2) Anser, thank you very much, but it doesn't that i want. When I press the one button, in the get put 1, if i press the second button, erase the get and put 2. I would like 12, not 2. Sorry for my english

Thanks
User avatar
Bayron
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Envio Teclas a un Get

Post by Bayron »

Para un Caracter:

Code: Select all | Expand

....
....
ACTION tecla('D',oget)


Para las demás teclas: (Por ejemplo la tecla de Inicio)

Code: Select all | Expand

....
....
ACTION (oGet:SetFocus(), sysRefresh(), oGet:KeyDown(VK_HOME))
...
....

 


Code: Select all | Expand


FUNCTION Tecla(letra,oget)
    oGet:SetFocus()
    SysreFresh()
    oGet:KeyChar(ASC(letra))
    oGet:Refresh()
   
RETURN NIL
 
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Antonio Linares
Site Admin
Posts: 42450
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 20 times
Been thanked: 58 times
Contact:

Re: Envio Teclas a un Get

Post by Antonio Linares »

Mike,

Pruébalo asi:

Code: Select all | Expand

#ifndef INPUT_MOUSE

#define INPUT_MOUSE     0
#define INPUT_KEYBOARD  1
#define INPUT_HARDWARE  2

typedef struct tagMOUSEINPUT {
    LONG    dx;
    LONG    dy;
    DWORD   mouseData;
    DWORD   dwFlags;
    DWORD   time;
    ULONG_PTR dwExtraInfo;
} MOUSEINPUT, *PMOUSEINPUT, FAR* LPMOUSEINPUT;

typedef struct tagKEYBDINPUT {
    WORD    wVk;
    WORD    wScan;
    DWORD   dwFlags;
    DWORD   time;
    ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT, FAR* LPKEYBDINPUT;

typedef struct tagHARDWAREINPUT {
    DWORD   uMsg;
    WORD    wParamL;
    WORD    wParamH;
} HARDWAREINPUT, *PHARDWAREINPUT, FAR* LPHARDWAREINPUT;

typedef struct tagINPUT {
    DWORD   type;

    union
    {
        MOUSEINPUT      mi;
        KEYBDINPUT      ki;
        HARDWAREINPUT   hi;
    };
} INPUT, *PINPUT, FAR* LPINPUT;

#endif

HB_FUNC( SENDKEY )
{
     INPUT input;

   input.type           = INPUT_KEYBOARD;
   input.ki.wVk         = hb_parnl( 1 );
   input.ki.wScan       = 0;
   input.ki.dwFlags     = 0;
   input.ki.time        = 0;
   input.ki.dwExtraInfo = 0;
     
   hb_retnl( SendInput( 1, &input, sizeof( input ) ) );
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Mike Serra
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Post by Mike Serra »

Antonio vamos por buen camino, ya los únicos errores que me salen son en todas las líneas donde aparece DWORD. me da la sensación que me hace falta algún include o librería

Gracias.
User avatar
Antonio Linares
Site Admin
Posts: 42450
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 20 times
Been thanked: 58 times
Contact:

Re: Envio Teclas a un Get

Post by Antonio Linares »

Mike,

Los obligatorios:

#include <windows.h>
#include <hbapi.h>
regards, saludos

Antonio Linares
www.fivetechsoft.com
Mike Serra
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Post by Mike Serra »

Antonio, al final, compiló, aunque el resultado no es el correcto. Cada vez que pulso un botón del teclado numérico, borra el contenido del get. Te escribo el código para saber qué puedo estar haciendo mal:

Code: Select all | Expand


redefine get oGetCantidad var nCantidad picture " 9999.99 €" id 202 of odlg FONT oFonts:oFontTextoNegritaExtraGrande ON CHANGE (nDevolucion:=oThis:nTotalVenta - val(cValtoChar(nCantidad)),oGetDevolucion:refresh()) valid (nDevolucion:=oThis:nTotalVenta - val(cValtoChar(nCantidad)) - ::nTotalVale - ::nTotalTarjeta - ::nTotalTalon,oGetDevolucion:refresh(),.t.)
 


Cada boton del teclado numerico está redefinido asi:

Code: Select all | Expand


redefine SBUTTON aoButtons[1]       id 301 OF odlg PROMPT "&7" FILENAME ".\bmp\BUTTONS\enter.bmp" ACTION (SendKeysGets(oGetCantidad,"7"),nDevolucion:=oThis:nTotalVenta - val(cValtoChar(nCantidad)),oGetDevolucion:refresh()) CRYSTAL NOBORDER COLORS CLR_WHITE, RGB(0,0,0) TEXT ON_BOTTOM FONT oFonts:oFontTextoNegritaExtraGrande
 


y por ultimo la funcion SendKeysGets esta así:

Code: Select all | Expand


procedure SendKeysGets(oWnd,cKey)
    oWnd:setfocus()
    SENDKEY(cKey)
    oWnd:refresh()
    oWnd:setfocus()
return

 
User avatar
Bayron
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Envio Teclas a un Get

Post by Bayron »

Mike, yo tengo un teclado funcionando correctamente con el ejemplo que te dí...

revisa SAMPLES\KEYBSIM.PRG
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Antonio Linares
Site Admin
Posts: 42450
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 20 times
Been thanked: 58 times
Contact:

Re: Envio Teclas a un Get

Post by Antonio Linares »

Prueba con:

procedure SendKeysGets(oWnd,cKey)
oWnd:setfocus()
SysRefresh()
SENDKEY(cKey)
return
regards, saludos

Antonio Linares
www.fivetechsoft.com
Mike Serra
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Post by Mike Serra »

Antonio, está todo semicorrecto :shock:. Te digo esto porque el problema está cuando la variable del get es numerica, ya que si es de texto, todo funciona correctamente. El ejemplo que hay en samples keybsim.prg me lo confirma. Con las ultimas modificaciones que me enviaste para en tema de SENDKEY, que al final conseguimos que funcionara, el resultado es el mismo que cuando usamos la variable numerica en el ejemplo de keybsim.

Como no se si tiene solucion, voy a plantear otro remedio.

Un Saludo,

P.D. Y muchisimas gracias por todo
User avatar
Antonio Linares
Site Admin
Posts: 42450
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 20 times
Been thanked: 58 times
Contact:

Re: Envio Teclas a un Get

Post by Antonio Linares »

Mike,

En samples\keybsim.prg los números funcionan bien pero ojo que hay un picture que solo permite escribirlos en la zona central:

REDEFINE GET oGet1 VAR cVar ID 143 OF oDlg PICTURE "AX-9999-AA"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Mike Serra
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Post by Mike Serra »

Antonio, creo que no me he explicado bien, Si la variable es caracter (cVar en el ejemplo lo es), funciona todo correctamente, por supuesto, con las limitaciones de la picture, pero si modificas el ejemplo y usas nVar, le asignas 0.00 y lo pruebas (cambiale la picture o se la quitas), no funciona correctamente. (funciona como todas las pruebas que he he hecho con sendkey)

Espero haberme explicado ahora mejor.

Un Saludo,
User avatar
Antonio Linares
Site Admin
Posts: 42450
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 20 times
Been thanked: 58 times
Contact:

Re: Envio Teclas a un Get

Post by Antonio Linares »

Mike,

te refieres a que solo permite escribir un dígito ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply