Question about SET KEY

Question about SET KEY

Postby driessen » Sat Nov 24, 2007 1:07 am

Hello,

If I use this code :
Code: Select all  Expand view
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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Sat Nov 24, 2007 11:33 am

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
Antonio Linares
Site Admin
 
Posts: 42079
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby driessen » Sat Nov 24, 2007 12:52 pm

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Sat Nov 24, 2007 1:06 pm

Michel,

Here you have it working:
Code: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42079
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby driessen » Sat Nov 24, 2007 10:21 pm

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 94 guests