Function keys

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Function keys

Post by serge_girard »

Hello,

Being lazy I remembered an application (don't know which anymore, but mainframe certainly) where one could store frequently used pieces of 'text' under F-keys.

I wanted to dynamically fill a F-key with a constant value and afterwards I want to copy the content to a textbox field in my form.

For example: suppose today I work a lot on a city, 'Luxembourg'. I want this variable name to be stored in public var
(let's say in c_FN_KEY_1 .. c_FN_KEY_12) in order to be kept under my F1..F12 keys. Every time I press a F1-key I want the word 'Luxembourg' to be copied to
the textbox where the focus is on. This way I it saves a lot of typing and possible mistakes.

All key-text are saved in a INI file for easy text-editing.

I encounter 2 problems :
1- F12 key is not working (known problem?)
2- Some text will not appear on the labels (LABEL &cFN) but will copied to the textboxes.

Code: Select all

#include "hmg.ch"
 

FUNCTION MAIN()
/****************/
PUBLIC c_FN_KEY_1               := ''  
PUBLIC c_FN_KEY_2               := '' 
PUBLIC c_FN_KEY_3               := ''
PUBLIC c_FN_KEY_4               := ''
PUBLIC c_FN_KEY_5               := ''
PUBLIC c_FN_KEY_6               := ''
PUBLIC c_FN_KEY_7               := ''
PUBLIC c_FN_KEY_8               := ''
PUBLIC c_FN_KEY_9               := ''
PUBLIC c_FN_KEY_10              := ''
PUBLIC c_FN_KEY_11              := ''
PUBLIC c_FN_KEY_12              := ''


BEGIN INI FILE ("fn.INI")

   GET c_FN_KEY_1     		SECTION "FN"			      ENTRY "F1"
   GET c_FN_KEY_2     		SECTION "FN"			      ENTRY "F2"
   GET c_FN_KEY_3     		SECTION "FN"			      ENTRY "F3"
   GET c_FN_KEY_4     		SECTION "FN"			      ENTRY "F4"
   GET c_FN_KEY_5     		SECTION "FN"			      ENTRY "F5"
   GET c_FN_KEY_6     		SECTION "FN"			      ENTRY "F6"
   GET c_FN_KEY_7     		SECTION "FN"			      ENTRY "F7"
   GET c_FN_KEY_8     		SECTION "FN"			      ENTRY "F8"
   GET c_FN_KEY_9     		SECTION "FN"			      ENTRY "F9"
   GET c_FN_KEY_10    		SECTION "FN"			      ENTRY "F10"
   GET c_FN_KEY_11    		SECTION "FN"			      ENTRY "F11"
   GET c_FN_KEY_12    		SECTION "FN"			      ENTRY "F12"

END INI




DEFINE WINDOW Form_1  ;
	AT 0,0	           ;
	WIDTH  500  ;
	HEIGHT 400 ;
	TITLE "F1..F12 "   ;	
	ICON  'proj';  	 
 
	ON KEY ESCAPE        ACTION {Form_1.Release}

   ON KEY F1            ACTION {PASTE_CONTENT_F_KEY(1) }	
   ON KEY F2            ACTION {PASTE_CONTENT_F_KEY(2) }	
   ON KEY F3            ACTION {PASTE_CONTENT_F_KEY(3) }	
   ON KEY F4            ACTION {PASTE_CONTENT_F_KEY(4) }	
   ON KEY F5            ACTION {PASTE_CONTENT_F_KEY(5) }	
   ON KEY F6            ACTION {PASTE_CONTENT_F_KEY(6) }	
   ON KEY F7            ACTION {PASTE_CONTENT_F_KEY(7) }	
   ON KEY F8            ACTION {PASTE_CONTENT_F_KEY(8) }	
   ON KEY F9            ACTION {PASTE_CONTENT_F_KEY(9) }	
   ON KEY F10           ACTION {PASTE_CONTENT_F_KEY(10) }	
   ON KEY F11           ACTION {PASTE_CONTENT_F_KEY(11) }	
   ON KEY F12           ACTION {PASTE_CONTENT_F_KEY(12) }	

   ON KEY CONTROL+F1 	ACTION {COPY_CONTENT_F_KEY(1) }	
   ON KEY CONTROL+F2 	ACTION {COPY_CONTENT_F_KEY(2) }	
   ON KEY CONTROL+F3 	ACTION {COPY_CONTENT_F_KEY(3) }	
   ON KEY CONTROL+F4 	ACTION {COPY_CONTENT_F_KEY(4) }	
   ON KEY CONTROL+F5 	ACTION {COPY_CONTENT_F_KEY(5) }	
   ON KEY CONTROL+F6 	ACTION {COPY_CONTENT_F_KEY(6) }	
   ON KEY CONTROL+F7 	ACTION {COPY_CONTENT_F_KEY(7) }	
   ON KEY CONTROL+F8 	ACTION {COPY_CONTENT_F_KEY(8) }	
   ON KEY CONTROL+F9 	ACTION {COPY_CONTENT_F_KEY(9) }	
   ON KEY CONTROL+F10	ACTION {COPY_CONTENT_F_KEY(10) }	
   ON KEY CONTROL+F11	ACTION {COPY_CONTENT_F_KEY(11) }	
   ON KEY CONTROL+F12	ACTION {COPY_CONTENT_F_KEY(12) }	

   nR := 7
   nC := 10
   FOR Z  := 1 TO 12
      cFN   := 'c_FN_KEY_' + ALLTRIM(STR(Z))
      cLB   := 'F' + ALLTRIM(STR(Z)) + '= '
       

      @ nR,nC LABEL &cFN  	;
         VALUE cLB + ALLTRIM(&cFN)	;
         WIDTH 100		;
         HEIGHT 10		;
         FONT 'Arial' SIZE 8		;
         ACTION Manage_FX() ;
         BACKCOLOR ORANGE	

      nC := nC + 110
      IF nC >= 400 
         nR := nR + 15
         nC := 10
      ENDIF
      
   NEXT


   @ 60,10 TEXTBOX TEST1		;
      WIDTH 300		;
      VALUE 'Press F1 to paste';    
      TOOLTIP ''		;
      FONT 'Arial' SIZE 8		;
      BACKCOLOR SILVER	;
      FONTCOLOR BLUE BOLD ;
      ON GOTFOCUS  SetProperty('Form_1', this.name ,'BackColor' , WHITE ) ;
      ON LOSTFOCUS SetProperty('Form_1', this.name ,'BackColor' , SILVER )  

   @ 90,10 TEXTBOX TEST2		;
      WIDTH 300		;
      VALUE 'Press CTRL-F1 to copy this text to F1 ';    
      TOOLTIP ''		;
      FONT 'Arial' SIZE 8		;
      BACKCOLOR SILVER	;
      FONTCOLOR BLUE BOLD ;
      ON GOTFOCUS  SetProperty('Form_1', this.name ,'BackColor' , WHITE ) ;
      ON LOSTFOCUS SetProperty('Form_1', this.name ,'BackColor' , SILVER )  
 
END WINDOW   
Form_1.center
Form_1.activate

RETURN





FUNCTION PASTE_CONTENT_F_KEY(x)
/********************************/
LOCAL cFOCUS	:= ThisWindow.FocusedControl	
LOCAL cOLD     := GetProperty(thiswindow.name, cFOCUS, 'Value' )
LOCAL n2, cFN

cFN   := 'c_FN_KEY_' + ALLTRIM(STR(x))
SetProperty(thiswindow.name, cFOCUS, 'Value', cOLD + &cFN)

n2 := LEN(GetProperty(thiswindow.name, cFOCUS, 'Value '   ) )
SetProperty(thiswindow.name, cFOCUS, 'Caretpos', n2 )  



RETURN

 
 


FUNCTION COPY_CONTENT_F_KEY(X)
/*****************************/ 
LOCAL cFOCUS	:= ThisWindow.FocusedControl		 
cFN := 'c_FN_KEY_' + ALLTRIM(STR(x)) 
&cFN := GetProperty(thiswindow.name, cFOCUS, 'Value')
 
FOR Z  := 1 TO 12
   cFN   := 'c_FN_KEY_' + ALLTRIM(STR(Z))
   cLB   := 'F' + ALLTRIM(STR(Z)) + '= '
   SetProperty(thiswindow.name, cFN, 'Value', cLB + &cFN)  
NEXT

SET_SECTION()


RETURN





FUNCTION Manage_FX()
/*******************/

IF !IsWIndowActive (Form_FX) 
  
   DEFINE WINDOW Form_FX ;
      AT 0,0 ;
      WIDTH  600 ;	 
      HEIGHT 600 ;	 
      TITLE 'Function keys ' 

      ON KEY ESCAPE ACTION {Form_FX.Release }



      @ 10,450 BUTTON bt_save  OF Form_FX ;
         CAPTION 'Save' ;
         PICTURE 'ADD' ;
         FONT 'Arial' SIZE 8      ;
         HEIGHT 86 ;    
         WIDTH  72 ;
         TOOLTIP 'New Item' ;
         ACTION save_fx() 

      nR    := 10
      FOR Z  := 1 TO 12
         LBX   := 'LB' + ALLTRIM(STR(Z))
         TBX   := 'TB' + ALLTRIM(STR(Z))
         LVA   := 'F'  + ALLTRIM(STR(Z))
         cFN   := 'c_FN_KEY_' + ALLTRIM(STR(Z))

      @ nR,10 LABEL &LBX	;
         VALUE LVA	;
         WIDTH 100		;
         HEIGHT 30		;
         FONT 'Arial' SIZE 10		;
         BACKCOLOR SILVER	;
         FONTCOLOR BLUE BOLD ;

      @ nR,120 TEXTBOX &TBX		;
         WIDTH 300		;
         VALUE &cFN;    
         TOOLTIP LVA	;
         MAXLENGTH 200	;
         FONT 'Arial' SIZE 10		;
         BACKCOLOR SILVER	;
         FONTCOLOR BLUE BOLD ;
         ON GOTFOCUS  SetProperty('Form_FX', this.name ,'BackColor' , WHITE ) ;
         ON LOSTFOCUS SetProperty('Form_FX', this.name ,'BackColor' , SILVER )  

         nR := nR + 35
      NEXT
 
   END WINDOW
  
   Form_FX.center
   Form_FX.activate
ELSE
   Form_FX.SetFocus  
ENDIF
RETURN






FUNCTION SAVE_FX() 
/******************/
LOCAL Z, TBX, ZZZ, cFN, cLB


FOR Z  := 1 TO 12
   TBX   := 'TB' + ALLTRIM(STR(Z))
   ZZZ   := GetProperty('Form_FX', tbx, 'Value') 
   cFN   := 'c_FN_KEY_' + ALLTRIM(STR(Z))
   &cFN  := ZZZ
NEXT
 
Form_FX.Release

FOR Z  := 1 TO 12
   cFN   := 'c_FN_KEY_' + ALLTRIM(STR(Z))
   cLB   := 'F' + ALLTRIM(STR(Z,2,0)) + '= '
   SetProperty('Form_1', cFN, 'Value', cLB + ALLTRIM(&cFN) )
NEXT
SET_SECTION()

RETURN



FUNCTION SET_SECTION()
/*********************/
BEGIN INI FILE ("fn.INI")
   SET SECTION "FN"	ENTRY "F1"   TO  c_FN_KEY_1     				      
   SET SECTION "FN"	ENTRY "F2"   TO  c_FN_KEY_2     				      
   SET SECTION "FN"	ENTRY "F3"   TO  c_FN_KEY_3     				      
   SET SECTION "FN"	ENTRY "F4"   TO  c_FN_KEY_4     				      
   SET SECTION "FN"	ENTRY "F5"   TO  c_FN_KEY_5     				      
   SET SECTION "FN"	ENTRY "F6"   TO  c_FN_KEY_6     				      
   SET SECTION "FN"	ENTRY "F7"   TO  c_FN_KEY_7     				      
   SET SECTION "FN"	ENTRY "F8"   TO  c_FN_KEY_8     				      
   SET SECTION "FN"	ENTRY "F9"   TO  c_FN_KEY_9     				      
   SET SECTION "FN"	ENTRY "F10"  TO  c_FN_KEY_10    				      
   SET SECTION "FN"	ENTRY "F11"  TO  c_FN_KEY_11    				      
   SET SECTION "FN"	ENTRY "F12"  TO  c_FN_KEY_12    				      
END INI

F.INI INI FILE

Code: Select all

[FN]
F1=SOUTH-AFRICA 
F2=UZBEKISTAN
F3=AUSTRALIA
F4=FRANCE
F5=HOLLAND
F6=TURKEY
F7=BELGIUM   
F8=DEUTSCHLAND       
F9=DANMARK   
F10=ISRAEL     
F11=LUXEMBOURG
F12=U.K.       
So if anyone can help the F12 issue and/or this strange label problem.
NB Clicking on the FN labels will open an form for extra editing!

Serge
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: Function keys

Post by trmpluym »

Hi Serge,

The F12 key problem can be fixed, see:

http://hmgforum.com/viewtopic.php?f=20& ... 2&start=10

Theo
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Function keys

Post by serge_girard »

Thx Theo and the late Pablo !

Serge
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Function keys

Post by andyglezl »

Hola Serge, porqué no utilizar un LISTBOX o COMBOBOX ?
Yo no he probado esto, pero pudiera funcionar...
*---------------------------------------------------------------------
Hi Serge, why not use a LISTBOX or COMBOBOX?
I have not tried this, but it could work ...



AutoFill
Add auto filling feature to a TextBox Control.

- Usage: Build an array for words to filling in TextBox entry
- Specify AutoFill() as ONCHANGE procedure of TextBox
- Specify AFKeySet() as ONGOTFOCUS procedure of TextBox
- Specify AFKeyRls() as ONLOSTFOCUS procedure of TextBox

- Example:
aCountries := {"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", ... }
ASORT( aCountries ) // This Array MUST be sorted

DEFINE TEXTBOX TextBoxCountries
ROW 48
COL 110
ONCHANGE AutoFill( aCountries )
ONGOTFOCUS AFKeySet( aCountries )
ONLOSTFOCUS AFKeyRls( )
END TEXTBOX

Authors:
Started by B. Esgici <esgici@gmail.com>
Enhanced by Roberto Lopez <mail.box.hmg@gmail.com> and S. Rathinagiri <srgiri@dataone.in>
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Function keys

Post by serge_girard »

Andres, Did you try my demo? See the difference!

Serge
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Function keys

Post by andyglezl »

Si, pero no veo el panorama completo de dicha función como tu lo ves, por eso sugerí el combobox...
Sobre el problema del F12, no se que pase. Y si utilizas ALT+Fnn ?
*-------------------------------------------------------------------------------------------------------------------------------
Yes, but I don't see the complete panorama of said function as you see it, that's why I suggested the combobox ...
About the F12 problem, I don't know what happens. What if you use ALT + Fnn?
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Function keys

Post by serge_girard »

Hi Andres, For the moment 11 function keys are more than enough, to me.
There are more possibilities if I want:

ALT+A...ALT+Z
ALT+0...ALT+9
ALT+F1...ALT+F12
ALT+BACK,ALT+TAB,ALT+RETURN,ALT+ESCAPE,ALT+END,ALT+HOME,ALT+LEFT,ALT+UP,
ALT+RIGHT,ALT+DOWN,ALT+INSERT,ALT+DELETE,ALT+PRIOR,ALT+NEXT

Shift Keys
SHIFT+A...SHIFT+Z
SHIFT+0...SHIFT+9
SHIFT+F1...SHIFT+F12
SHIFT+BACK,SHIFT+TAB,SHIFT+RETURN,SHIFT+ESCAPE,SHIFT+END,SHIFT+HOME,
SHIFT+LEFT,SHIFT+UP,SHIFT+RIGHT,SHIFT+DOWN,SHIFT+INSERT,SHIFT+DELETE
SHIFT+PRIOR,SHIFT+NEXT

You can see the meaning as a 'macro' to fill up any TEXTBOX or EDITBOX with a value under the F-key.
So if you need to type in your name in your application more than 10 times a day, you can store your name under F1. Then focus on a TEXTBOX where you would normally type in, again, your name. Now press F1 and the magic happens. Then after a few hours you will have to type in another name. Change content and ready! That's all, very basic and simple and it works (F12 not yet but Theo noticed this solution: http://hmgforum.com/viewtopic.php?f=2 ... tart=10 )

Serge
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Function keys

Post by andyglezl »

Hola Serge (Solo como información)
A esto me refería con un COMBOBOX ya que yo lo hice de esta forma...
Con esto puedo COPIAR el dato y PEGARLO en cualquier parte y en cualquier programa.
*----------------------------------------------------------------------------------------------------------
Hi Serge (Only information)
This is what I meant with a COMBOBOX since I did it this way ...
With this I can COPY the data and PASTE it anywhere and in any program.

Control-V.gif
Control-V.gif (1.22 MiB) Viewed 2609 times
Andrés González López
Desde Guadalajara, Jalisco. México.
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Function keys

Post by franco »

Serge, I use a table for this.
At start of main program open table and set function keys.
When I want to modify function keys I have a procedure to edit then and reset them before leaving procedure.
I use alt+, shift+ and ctrl+ for this area because I like to have regular f keys for other areas of program for fast entry`s.
Franco
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Function keys

Post by serge_girard »

Thanks all for ideas!

Serge
There's nothing you can do that can't be done...
Post Reply