TECLA F8 Y LASTKEY()

HMG en Español

Moderator: Rathinagiri

Post Reply
abinfra
Posts: 68
Joined: Sat Jan 25, 2014 7:25 am
DBs Used: DBF

TECLA F8 Y LASTKEY()

Post by abinfra »

Hola a todos.

Os agradecería me ayudes con el siguiente tema:
¿Que código puedo usar para que LASTKEY() tome el valor de la tecla F8 como si la hubiera pulsado manualmente?

Para escape o intro utilizo:
KEYBOARD CHR(27)
KEYBOARD CHR(13)

Saludos cordiales.
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: TECLA F8 Y LASTKEY()

Post by BeGeS »

Supongo que CHR(-7)

Pero es que ocurre una cosa:

En Clipper/Harbour tenemos...

#define K_F7 -6
#define K_F8 -7
#define K_F9 -8

Mientras que en HMG...

#define VK_F7 118
#define VK_F8 119
#define VK_F9 120


Prueba a ver... :roll:
I get by with a little help from my friends
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: TECLA F8 Y LASTKEY()

Post by edk »

In such cases, I use two codes to trigger an action, eg: Lastkey () = - 7 .OR. Lastkey () = 250
Then it works correctly when you press the f8 key and on: keyboard chr(250)
abinfra
Posts: 68
Joined: Sat Jan 25, 2014 7:25 am
DBs Used: DBF

Re: TECLA F8 Y LASTKEY()

Post by abinfra »

Gracias BeGeS y edk.

Edk, solo me ha funcionado tu opción, muchas gracias.


P.D.
Ejemplo de lo hecho:

//Andes de DBEEDIT()
//La variable "Control", controla si vengo de procedimiento o función
If Control == 1
USE ALMACEN INDEX ALMACEN,ALMACENA
SET ORDER TO 2
ELSE
Controle := 1
CLEAR GETS
CLEAR TYPEAHEAD
KEYBOARD CHR(250)
ENDIF
...
DBEDIT(...)
...
DO CASE
...
//Si he pulsado manualmente en el teclado la tecla F8
//O he puesto mediante código el valor de LASTKEY() = 250,
//para que si vengo de otra función no tener que pulsar manualmente en el teclado la tecla F8
CASE LASTKEY()=-7 .OR. LASTKEY()=250
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: TECLA F8 Y LASTKEY()

Post by edk »

One more solution (more elegant): instead of "fake key" KEYBOARD CHR(250) you can use: _PushKey(VK_F8)
Then only CASE LASTKEY()=-7 is enough.

Code: Select all

#include "hmg.ch"

REQUEST HB_GT_WIN_DEFAULT

Function Main
CLS
DO WHILE LASTKEY()#27
	inkey(0)
	IF LASTKEY()=-6		//The F7 key emulates F8
		_PushKey(VK_F8)
		inkey(0)
	ENDIF
	@1,1 SAY LASTKEY()
ENDDO

RETURN Nil
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: TECLA F8 Y LASTKEY()

Post by BeGeS »

abinfra wrote: Sun Sep 10, 2017 9:20 pm CLEAR TYPEAHEAD
KEYBOARD CHR(250)
ENDIF
...
DBEDIT(...)
...
DO CASE
...
//Si he pulsado manualmente en el teclado la tecla F8
//O he puesto mediante código el valor de LASTKEY() = 250,
//para que si vengo de otra función no tener que pulsar manualmente en el teclado la tecla F8
CASE LASTKEY()=-7 .OR. LASTKEY()=250
El hecho de que KEYBOARD() mande un carácter al buffer no significa que actualice el valor de LASTKEY(). Para esto hace falta poner a continuación INKEY():

KEYBOARD(250) ; INKEY()

Entonces sí tendras 250 como valor de LASTKEY()

* * * * * * * * *
(Aunque el tema sea "HMG en español", es mejor seguir la norma)

The fact that KEYBOARD() sends a character to the buffer does not mean that it updates the value of LASTKEY(). To do this, you must
enter INKEY():

KEYBOARD(250) ; INKEY()

Then you will have 250 as value of LASTKEY()
I get by with a little help from my friends
abinfra
Posts: 68
Joined: Sat Jan 25, 2014 7:25 am
DBs Used: DBF

Re: TECLA F8 Y LASTKEY()

Post by abinfra »

Gracias edk y BeGeS.

BeGeS, he probado poniendo después de KEYBOARD CHR(250), sin poner INKEY(), WAIT LASTKEY() y me da: 250.
Si pongo INKEY() después de KEYBOARD CHR(250), no se ejecuta el código que tengo después de:
CASE LASTKEY()=-7 .OR. LASTKEY()=250

Saludos cordiales.
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: TECLA F8 Y LASTKEY()

Post by BeGeS »

La cuestión era que KEYBOARD() envía un carácter al buffer, pero LASTKEY() no queda actualizada. Al menos eso dice la teoría.

Probablemente el mandato WAIT saque el contenido del buffer, por lo que INKEY() ya estaría de más. (Nunca he usado WAIT).

De todos modos lo importante es que te funcione como querías, pues nada más lejos de mi intención que andar enredando. :oops:

Un saludo. ;)
I get by with a little help from my friends
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: TECLA F8 Y LASTKEY()

Post by edk »

BeGeS wrote: Thu Sep 14, 2017 9:44 pm La cuestión era que KEYBOARD() envía un carácter al buffer, pero LASTKEY() no queda actualizada. Al menos eso dice la teoría.
abinfra wrote: Sun Sep 10, 2017 9:20 pm P.D.
Ejemplo de lo hecho:

//Andes de DBEEDIT()
//La variable "Control", controla si vengo de procedimiento o función
If Control == 1
USE ALMACEN INDEX ALMACEN,ALMACENA
SET ORDER TO 2
ELSE
Controle := 1
CLEAR GETS
CLEAR TYPEAHEAD
KEYBOARD CHR(250)
ENDIF
...
DBEDIT(...)
...
DO CASE
...
//Si he pulsado manualmente en el teclado la tecla F8
//O he puesto mediante código el valor de LASTKEY() = 250,
//para que si vengo de otra función no tener que pulsar manualmente en el teclado la tecla F8
CASE LASTKEY()=-7 .OR. LASTKEY()=250
abinfra wrote: Tue Sep 12, 2017 3:19 pm
BeGeS, he probado poniendo después de KEYBOARD CHR(250), sin poner INKEY(), WAIT LASTKEY() y me da: 250.
Si pongo INKEY() después de KEYBOARD CHR(250), no se ejecuta el código que tengo después de:
CASE LASTKEY()=-7 .OR. LASTKEY()=250

Saludos cordiales.
DBEdit() successively reads the keyboard buffer, so the lastkey() inside dbedit() returns the values ​​read in turn.
Using inkey() (or WAIT) before calling dbedit() causes the keyboard buffer to be drained.
For this reason, Dbedit() will expect to fill the keyboard buffer and the lastkey() inside dbedit() will not return the value of the last keyboard chr() command.
abinfra
Posts: 68
Joined: Sat Jan 25, 2014 7:25 am
DBs Used: DBF

Re: TECLA F8 Y LASTKEY()

Post by abinfra »

Gracias edk.
Saludos cordiales.
Post Reply