Page 1 of 4
Set function key to a Value
Posted: Sat Jul 23, 2016 7:26 am
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

Re: Set function key to a Value
Posted: Sat Jul 23, 2016 7:33 am
by serge_girard
Franco,
you can use:
ON KEY F1 ACTION {somefunction() }
Serge
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 7:37 am
by franco
Serge
how could I say
ON KEY F22 KEYBOARD '123'
fRANCO
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 9:39 am
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
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 10:50 am
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
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 12:14 pm
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
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 12:16 pm
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' )
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 1:03 pm
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
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 2:35 pm
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
Re: Set function key to a Value
Posted: Sat Jul 23, 2016 3:49 pm
by trmpluym
Roberto,
You are right, thanks for improving the demo !
Franco can go on now
Theo