Page 1 of 1
Question about SET KEY
Posted: Sat Nov 24, 2007 1:07 am
by driessen
Hello,
If I use this code :
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.
Posted: Sat Nov 24, 2007 11:33 am
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
Posted: Sat Nov 24, 2007 12:52 pm
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.
Posted: Sat Nov 24, 2007 1:06 pm
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
Posted: Sat Nov 24, 2007 10:21 pm
by driessen
Antonio,
Thanks a lot for your help.
I'll try it out ASAP.
Have a good weekend.