Page 1 of 2

Envio Teclas a un Get

Posted: Sat Oct 15, 2011 5:47 am
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,

Re: Envio Teclas a un Get

Posted: Sat Oct 15, 2011 9:21 am
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

Re: Envio Teclas a un Get

Posted: Sat Oct 15, 2011 9:39 am
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

Re: Envio Teclas a un Get

Posted: Sat Oct 15, 2011 6:13 pm
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

Re: Envio Teclas a un Get

Posted: Sat Oct 15, 2011 7:13 pm
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
 

Re: Envio Teclas a un Get

Posted: Sat Oct 15, 2011 8:22 pm
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 ) ) );
}
 

Re: Envio Teclas a un Get

Posted: Sun Oct 16, 2011 9:14 am
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.

Re: Envio Teclas a un Get

Posted: Sun Oct 16, 2011 10:28 am
by Antonio Linares
Mike,

Los obligatorios:

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

Re: Envio Teclas a un Get

Posted: Sun Oct 16, 2011 9:23 pm
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

 

Re: Envio Teclas a un Get

Posted: Sun Oct 16, 2011 10:02 pm
by Bayron
Mike, yo tengo un teclado funcionando correctamente con el ejemplo que te dí...

revisa SAMPLES\KEYBSIM.PRG

Re: Envio Teclas a un Get

Posted: Sun Oct 16, 2011 10:43 pm
by Antonio Linares
Prueba con:

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

Re: Envio Teclas a un Get

Posted: Tue Oct 18, 2011 9:40 am
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

Re: Envio Teclas a un Get

Posted: Tue Oct 18, 2011 9:52 am
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"

Re: Envio Teclas a un Get

Posted: Tue Oct 18, 2011 10:03 am
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,

Re: Envio Teclas a un Get

Posted: Tue Oct 18, 2011 12:34 pm
by Antonio Linares
Mike,

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