Re: Keystrokes simulations

new topic     » goto parent     » topic index » view thread      » older message » newer message

Sergio Gelli wrote:
 
> I use with success the below code line:
> 
>  ii=invokeHandler(PushButton34, w32HClick, {})	
> 
> But the next line don't work:
> 
>   ii = invokeHandler(PushButton34, VK_TAB, {})

That function is used to call the user defined handler for one of the win32lib
event types, and not used to simulate keystrokes.
 
> The target is simulates the TAB key to change the focus 
> to another objects inside an windows.

Here is a sample program that could help you...
include win32lib.ew
without warning

integer Win
integer box1
integer box2
integer box3
integer box4
integer btn1
integer SB

function change_focus(sequence pName)
    integer newid

    newid = getNameId(pName)
    if newid > 0 then
        setFocus(newid)
    end if
    return newid
end function

procedure onFocus_id(atom id, atom event, sequence params)
    setText(SB, "Focus is now on '" & getIdName(id) & "'")
end procedure

procedure Key_Box4(atom id, atom event, sequence params)
    if params[1] = VK_ENTER then
        if change_focus(getText(id)) > 0 then
            setText(id, "") -- clear the name of the control
            returnValue(-1) -- tell win32lib to not auto setfocus on return
        end if
    end if
end procedure

procedure Click_Btn1(atom id, atom event, sequence params)
    setFocus(box1)
end procedure

procedure main()

    Win  = create( Window, "TEST", 0, 50, 50, 300, 200,0 )
    box1 = create( EditText, "Box 1", Win, 5, 10, 90, 22, 0)
    box2 = create( EditText, "Box 2", Win, 5, 40, 90, 22, 0)
    box3 = create( EditText, "Box 3", Win, 5, 70, 90, 22, 0)
    box4 = create( EditText, "Box 4", Win, 105, 10, 90, 22, 0)
    btn1 = create( Button, "Set Focus", Win, 105,110, 90, 22, 0)
    SB   = create( StatusBar, "", Win, 0, 0, 0, 0, 0)

    setText(btn1, "Goto Box 1")
    setHint(box4, "Enter the name of control to set focus to it.")
setHandler({box1,box2,box3,box4,btn1},w32HGotFocus,
    routine_id("onFocus_id"))
    setHandler(btn1, w32HClick, routine_id("Click_Btn1"))
    setHandler(box4, w32HKeyPress, routine_id("Key_Box4"))
    WinMain({Win, box1},Normal)
end procedure

main()


Please note that when the Enter key is pressed in an EditText control, Win32lib
will automatically move focus to the next control.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu