Set function key to a Value

Moderator: Rathinagiri

franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Set function key to a Value

Post by franco »

Hello again,
I am trying to set function keys to values like I did in Clipper.
Clipper command Set function 22 to '123'
When ever I hit ctrl+function 2 in a inputbox or textbox it would type 123 in the box.
I can not get this to work in HMG, I know there must be a way to do it.

Thanks in advance........... Franco :?
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Set function key to a Value

Post by serge_girard »

Franco,

you can use:

ON KEY F1 ACTION {somefunction() }


Serge
There's nothing you can do that can't be done...
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Set function key to a Value

Post by franco »

Serge
how could I say
ON KEY F22 KEYBOARD '123'
fRANCO
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Set function key to a Value

Post by serge_girard »

Franco,

Try this:

Code: Select all

DEFINE WINDOW Form_1
...
ON KEY F1 ACTION somefunction() 
...
END WINDOW



FUNCTION Somefunction()
keyboard '123'
RETURN
There's nothing you can do that can't be done...
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Set function key to a Value

Post by trmpluym »

Franco

If you use the GUI the command "keyboard" does not work.

When i assume the window (form) is named Form_1, you can use this:

Code: Select all

ON KEY F1 OF Form_1 ACTION Somefunction()

FUNCTION Somefunction()

_Pushkey(VK_1)		// Press "1"
_Pushkey(VK_2)		// Press "2"
_Pushkey(VK_3)		// Press "3"

RETURN
Theo
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Set function key to a Value

Post by Roberto Lopez »

Hi Franco,

Alternatively, you could do this:

Code: Select all

ON KEY F1 OF Form_1 ACTION Somefunction()

FUNCTION Somefunction()

    cFocusedControl := GetProperty( 'Form_1' , 'FocusedControl' )
    SetProperty( 'Form_1' , FocusedControl , 'Value' , '123' )

RETURN
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Set function key to a Value

Post by Roberto Lopez »

Hi Franco,

Alternatively, you could do this:

Code: Select all

ON KEY F1 OF Form_1 ACTION Somefunction()

FUNCTION Somefunction()

    cFocusedControl := GetProperty( 'Form_1' , 'FocusedControl' )
    SetProperty( 'Form_1' , cFocusedControl , 'Value' , '123' )

RETURN
Or:

Code: Select all

ON KEY F1 OF Form_1 ACTION SetProperty( 'Form_1' , GetProperty( 'Form_1' , 'FocusedControl' ) , 'Value' , '123' )
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Set function key to a Value

Post by trmpluym »

Hi Franco,

A little addition to the very nice code of Roberto. To preserve errors when pressing F1 check if the focussed control is an EDITBOX.

Code: Select all

FUNCTION Somefunction()

cFocusedControl := GetProperty( 'Form_1' , 'FocusedControl' )

IF GetControlType( cFocusedControl , "Form_1") == "EDITBOX" 
    SetProperty( 'Form_1' , cFocusedControl , 'Value' , '123' )
ENDIF 

RETURN
In addition, to be perfect, you also have to check if the "EDITBOX" is ReadOnly.

Theo
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Set function key to a Value

Post by Roberto Lopez »

Theo:

AFAIR, the values returned by GetControlType() are the following for text inputs:

For TextBox:

"NUMTEXT", "TEXT","MASKEDTEXT"

For EditBox:

"EDIT" (not 'EDITBOX' )

So, The correct code should be:

Code: Select all

FUNCTION Somefunction()

cFocusedControl := GetProperty( 'Form_1' , 'FocusedControl' )

IF GetControlType( cFocusedControl , "Form_1") == "EDIT" .Or. GetControlType( cFocusedControl , "Form_1") == "TEXT" 
    SetProperty( 'Form_1' , cFocusedControl , 'Value' , '123' )
ENDIF 

RETURN
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Set function key to a Value

Post by trmpluym »

Roberto,

You are right, thanks for improving the demo !

Franco can go on now :D

Theo
Post Reply