Mr. Duch
By the time the VK button is pressed, the previous active get already lost focus, and any logic you use to find the focused control, the result is the VK button.
For this application the best possible logic is what you adopted:
oGet[1]:bGotFocus := {|| x := 1 }
Encouraged by your posting, I made a simple program, basically using your logic.
#include 'fivewin.ch'
#define VK_TITLE "Free Virtual Keyboard (<!-- w --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">www.FreeVirtualKeyboard.com</a><!-- w -->)"
//----------------------------------------------------------------------------//
function Main()
local oDlg, oFont
local oGet, nPos // save current get and cursor position
local cVar1 := PadR( "First Get", 80 )
local cVar2 := PadR( "Second Get", 80 )
local nVar := 123456.89
local dVar := Date()
SET DATE BRITISH
SET CENTURY ON
SetGetColorFocus()
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 300,200 PIXEL FONT oFont
@ 10, 10 GET cVar1 SIZE 130,12 PIXEL OF oDlg
@ 24, 10 GET cVar2 SIZE 130,12 PIXEL OF oDlg
@ 38, 10 GET nVar PICTURE '999,999.99' SIZE 50,12 PIXEL OF oDlg RIGHT
@ 38, 90 GET dVar SIZE 50,12 PIXEL OF oDlg
AEval( oDlg:aControls, { |oCtrl| oCtrl:bGotFocus := { |o| oGet := o } } )
@ 80, 10 BUTTON "VK" SIZE 40,12 PIXEL OF oDlg ;
ACTION ( nPos := oGet:nPos, ToggleVK(), ReFocusGet( oGet, nPos ) )
ACTIVATE DIALOG oDlg CENTERED
PostMessage( VkWnd(), WM_CLOSE )
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function ToggleVK()
local hVK := VkWnd()
if Empty( hVK )
WinExec( "FreeVK.Exe" )
elseif IsIconic( hVK ) .or. ! IsWindowVisible( hVK )
ShowWindow( hVK, 8 ) // sHOW NORMAL
else
ShowWindow( hVK, 0 ) // HIDE
endif
return nil
//----------------------------------------------------------------------------//
static function VkWnd()
static hWndVK := 0
if ! IsWindow( hWndVK )
hWndVK := FindWindow( 0, VK_TITLE )
endif
return hWndVK
//----------------------------------------------------------------------------//
static function ReFocusGet( oGet, nPos )
oGet:SetFocus() // for character gets, this is enough
if oGet:oGet:Type != 'C'
oGet:SetPos( nPos )
if oGet:oGet:Type == 'N' .and. nPos > 1
oGet:KeyDown( VK_LEFT )
oGet:KeyDown( VK_RIGHT )
endif
endif
return nil
//----------------------------------------------------------------------------//
Please compile and see how this works on character, date and numeric gets.
Here, the VK button toggles the VKeyBoard.