FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Envio Teclas a un Get
Posts: 297
Joined: Fri Apr 14, 2006 05:52 PM
Envio Teclas a un Get
Posted: Sat Oct 15, 2011 05:47 AM

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,

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Envio Teclas a un Get
Posted: Sat Oct 15, 2011 09:21 AM
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 (fw): Select all Collapse
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
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Envio Teclas a un Get
Posted: Sat Oct 15, 2011 09:39 AM
Did you try

Code (fw): Select all Collapse
 @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 (fw): Select all Collapse
#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
Posts: 297
Joined: Fri Apr 14, 2006 05:52 PM
Re: Envio Teclas a un Get
Posted: Sat Oct 15, 2011 06:13 PM
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 (fw): Select all Collapse
#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
Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Envio Teclas a un Get
Posted: Sat Oct 15, 2011 07:13 PM
Para un Caracter:
Code (fw): Select all Collapse
....
....
ACTION tecla('D',oget)


Para las demás teclas: (Por ejemplo la tecla de Inicio)
Code (fw): Select all Collapse
....
....
ACTION (oGet:SetFocus(), sysRefresh(), oGet:KeyDown(VK_HOME))
...
....


Code (fw): Select all Collapse
FUNCTION Tecla(letra,oget) 
    oGet:SetFocus()
    SysreFresh()
    oGet:KeyChar(ASC(letra))
    oGet:Refresh()
    
RETURN NIL

=====>

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

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Envio Teclas a un Get
Posted: Sat Oct 15, 2011 08:22 PM
Mike,

Pruébalo asi:

Code (fw): Select all Collapse
#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
Posts: 297
Joined: Fri Apr 14, 2006 05:52 PM
Re: Envio Teclas a un Get
Posted: Sun Oct 16, 2011 09:14 AM

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.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Envio Teclas a un Get
Posted: Sun Oct 16, 2011 10:28 AM

Mike,

Los obligatorios:

include <windows.h>

include <hbapi.h>

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 297
Joined: Fri Apr 14, 2006 05:52 PM
Re: Envio Teclas a un Get
Posted: Sun Oct 16, 2011 09:23 PM
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 (fw): Select all Collapse
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 (fw): Select all Collapse
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 (fw): Select all Collapse
procedure SendKeysGets(oWnd,cKey)
    oWnd:setfocus()
    SENDKEY(cKey)
    oWnd:refresh()
    oWnd:setfocus()
return
Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Envio Teclas a un Get
Posted: Sun Oct 16, 2011 10:02 PM

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

revisa SAMPLES\KEYBSIM.PRG

=====>

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

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Envio Teclas a un Get
Posted: Sun Oct 16, 2011 10:43 PM

Prueba con:

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 297
Joined: Fri Apr 14, 2006 05:52 PM
Re: Envio Teclas a un Get
Posted: Tue Oct 18, 2011 09:40 AM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Envio Teclas a un Get
Posted: Tue Oct 18, 2011 09:52 AM

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
Posts: 297
Joined: Fri Apr 14, 2006 05:52 PM
Re: Envio Teclas a un Get
Posted: Tue Oct 18, 2011 10:03 AM

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,

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Envio Teclas a un Get
Posted: Tue Oct 18, 2011 12:34 PM

Mike,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com