# Emulating another Windows Shortcut Key

This program uses the same technique as the "minimize windows on the desktop" example, and goes a little further.

First it opens the [Find] dialog box, and then types a filename sequence into that box.

This is followed by a VK_RETURN key, which then causes the dialog to search for the chosen file.

Note:
If you try to send a sequence to this dialog box *without* converting it first, you'll get a real mess... ;-)

-- findfiles.exw

    include win32lib.ew
    without warning

    constant
    -- our window, menues, and buttons.
    mystyle={WS_CAPTION,WS_SYSMENU,WS_THICKFRAME},
    Win1=create(Window,"Try It !",0,Default,Default,300,150,mystyle),
    Sample=create(Menu,"Sample",Win1,0,0,0,0,0),
    About=create(MenuItem,"About",Sample,0,0,0,0,0),
    Leave=create(MenuItem,"Eξt",Sample,0,0,0,0,0),
    Button1=create(PushButton,"Find File",Win1,10,10,50,25,0),
    -- .. two new functions,
    zVkKeyScan=registerw32Function(user32,"VkKeyScanA",{C_INT},C_INT),
    zkeybd_event=registerw32Function( user32,
                 "keybd_event", { C_INT, C_INT, C_INT, C_INT }, C_INT ),

    -- and two new constants.
    KEYEVENTF_KEYUP = 2,
    FindFiles = #46   -- "F"

    atom jk
    sequence ex,ex2
    ex2={}
    ex="findfiles.exw" -- will handle '\r'
    -- turn the sequence into key scan codes.
    for i=1 to length(ex) do
    ex2=ex2 & w32Func(zVkKeyScan,{ex[i]})
    end for
    -- make sure we only use 8 bits.
    ex2=and_bits(#FF,ex2)

    procedure find()
    -- open up the [Find] dialog box.
    jk = w32Func(zkeybd_event, {VK_LWIN, 0, 0, 0 } )
    jk = w32Func(zkeybd_event, {FindFiles, 0, 0, 0 } )
    jk = w32Func(zkeybd_event, {VK_LWIN, 0, KEYEVENTF_KEYUP, 0 } )
    -- delay, for a sec.
    sleep(1)
    -- send out our converted sequence in this loop.
    for i = 1 to length(ex2) do
    jk = w32Func(zkeybd_event, {ex2[i], 0, 0, 0 } )
    end for
    sleep(1)
    -- then, hit the [Return] key...
    jk = w32Func(zkeybd_event, {VK_RETURN, 0, 0, 0 } )
    end procedure
    --
    onClick[Button1]=routine_id("find")

    procedure about()
    jk = message_box("--- 'tutorial' demo, thanks to VB",
    "...another", 0 )
    end procedure
    --
    onClick[About]=routine_id("about")

    procedure leave()
       closeWindow(Win1)
    end procedure
    --
    onClick[Leave]=routine_id("leave")

    WinMain(Win1,Normal)
    --------

I've included another demo, which emulates all the Win keyboard shortcut keys I could find information on, so try it out too. ( WinKeys.exw )
'Typing' data into the [Run] dialog box was even trickier.. :(

..end of lesson.

CONTENTS