Question about SET KEY

Post Reply
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Question about SET KEY

Post by driessen »

Hello,

If I use this code :

Code: Select all

SET KEY VK_F5 TO TestPro
then the function TestPro() will be executed if the F5-key is pressed.

But now my question :

How can I read in another part of my appliction to which function the F5-key is linked ?

Thank you.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Michel,

You can't unless you store the function name yourself, and later on you search for it:

public aKeys := {}

SET KEY VK_F5 TO TestPro

AAdd( aKeys, { VK_F5, "TestPro" } )

You could modify the #xcommand SET KEY ... so it does it automatically for you
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Antonio,

Thanks a lot for your answer.

Until now, I never used #xcommand.

Please could you tell me how to solve my problem using #xcommand ?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Michel,

Here you have it working:

Code: Select all

#include "FiveWin.ch"

#command SET KEY <n> TO <proc> ;
      => SetKey( <n>, {|p, l, v| <proc>(p, l, v)} ) ;;
         AddKey( <n>, <(proc)> ) 

memvar aKeys

function Main()

   public aKeys := {}

   SET KEY VK_F5 TO Test

   MsgInfo( KeyProc( VK_F5 ) )

   SET KEY VK_F5 TO Another

   MsgInfo( KeyProc( VK_F5 ) )

return nil

function AddKey( nKey, cProc )

   local nAt

   if Len( aKeys ) == 0 .or. ( nAt := AScan( aKeys, { | a | a[ 1 ] == nKey } ) ) == 0
      AAdd( akeys, { nKey, cProc } )
   else
      aKeys[ nAt ] = { nKey, cProc }
   endif

return nil

function KeyProc( nKey )   

   local nAt := AScan( aKeys, { | a | a[ 1 ] == nKey } )

   if nAt != 0
      return aKeys[ nAt ][ 2 ]
   endif

return ""

function Test()

return nil

function Another()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Antonio,

Thanks a lot for your help.

I'll try it out ASAP.

Have a good weekend.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Post Reply