Envio Teclas a un Get

Envio Teclas a un Get

Postby Mike Serra » Sat Oct 15, 2011 5: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,
Mike Serra
 
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Postby Antonio Linares » Sat Oct 15, 2011 9: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: Select all  Expand view
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
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Envio Teclas a un Get

Postby anserkk » Sat Oct 15, 2011 9:39 am

Did you try

Code: Select all  Expand view
@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 view
#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
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Envio Teclas a un Get

Postby Mike Serra » Sat Oct 15, 2011 6: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: Select all  Expand view

#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
Mike Serra
 
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Postby Bayron » Sat Oct 15, 2011 7:13 pm

Para un Caracter:
Code: Select all  Expand view
....
....
ACTION tecla('D',oget)


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

 


Code: Select all  Expand view

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
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Envio Teclas a un Get

Postby Antonio Linares » Sat Oct 15, 2011 8:22 pm

Mike,

Pruébalo asi:

Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Envio Teclas a un Get

Postby Mike Serra » Sun Oct 16, 2011 9: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.
Mike Serra
 
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Postby Antonio Linares » Sun Oct 16, 2011 10:28 am

Mike,

Los obligatorios:

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Envio Teclas a un Get

Postby Mike Serra » Sun Oct 16, 2011 9: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: Select all  Expand view

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 view

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 view

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

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

Re: Envio Teclas a un Get

Postby Bayron » 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
(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
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Envio Teclas a un Get

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Envio Teclas a un Get

Postby Mike Serra » Tue Oct 18, 2011 9: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
Mike Serra
 
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Postby Antonio Linares » Tue Oct 18, 2011 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Envio Teclas a un Get

Postby Mike Serra » 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,
Mike Serra
 
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: Envio Teclas a un Get

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests