Show how to link user defined methods to user defined keys.

An example of this is the facility provided by emacs for key bindings.

These key bindings may be application-specific or system-wide; state which you have done.




include pGUI.e
 
function C_Keyed(Ihandle /*ih*/, atom /*c*/)
-- (Note without K_c below this does not respond to 'c', just 'C')
    ?"you pressed C"
    return IUP_DEFAULT
end function
 
procedure F2_keyed()
    ?"you pressed F2"
end procedure
 
function key_cb(Ihandle /*ih*/, atom c)
    if c=K_F2 then F2_keyed()
    elsif c=K_ESC then return IUP_CLOSE
    end if
    return IUP_DEFAULT
end function
 
IupOpen()
Ihandle dlg = IupDialog(IupLabel("hello"),"TITLE=\"Press F2\"")
IupSetCallback(dlg, "K_C", Icallback("C_Keyed"))
--IupSetCallback(dlg, "K_c", Icallback("C_Keyed"))
IupSetCallback(dlg, "K_ANY", Icallback("key_cb"))
IupShow(dlg)
if platform()!=JS then
    IupMainLoop()
    IupClose()
end if
