Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[view] field key trapping hook [patch]!

 [1/3] from: moliad::aei::ca at: 26-Aug-2006 3:03


here is a patch function which will allow you guys the capability to trap key events outside of the normal view operation. basically, you can trap key events and do anything you like with them without breaking normal view field input. When you are done, you decide if you want those key presses to continue to the normal text editing, by returning true or false in your hook function. in theory this is only guaranteed to work for version 1.3 , but it might work in older versions too. ;-------------------------------------------- the patching func ----------------------------------------------- hookup-field: func [ face [object!] hook [function!] /all "all fields sharing the same feel as the supplied face will be hooked" /local blk bword ][ unless all [ face/feel: make face/feel []; appy the hook to this field only. ] engage: get in face/feel 'engage blk: at third second :engage 6 bword: second second :engage change/only blk bind compose/deep [unless hook face event (blk)] bword ] ;------------------------------------------------------------------------------------------- here is a short example on how to use this, you can replace the key-hook by any appropriate function you need, obviously. This example simply unfocuses the field when escape is pressed, without calling the action func. something I've often found usefull. ;---------------------------------- an examble using the patch ----------------------------------------------------- key-hook: func [face event][ ; escape key calls unfocus! (without calling action) either event/key = #"^[" [ unfocus face ; we consumed the event, do not let view know about it. true ][ ; we did not consume the event, continue as normal. false ] ] view/new layout [fld: field button "close" [unview]] hookup-field fld :key-hook do-events ;------------------------------------------------------- have fun :-) -MAx

 [2/3] from: moliad::aei::ca at: 27-Aug-2006 23:10

Re: [view] field, input filter hook !


hi again, Using the little patch I released yesterday, I tought I'd release another little input hook function which is also very usefull... an input filter. Use this to create integer or decimal field boxes, just replace the key-hook in last example by this one and you get a field which only accepts decimal characters (plus arrows, tab, enter, esc, home, end). changing the characters in charset, you can adapt this filter to what you need. have fun! -MAx ;-------------------------------------------------- chars: charset [#"0" - #"9" "."] key-hook: func [ face event /local ignore ][ if any [ ignore: parse to-string event/key [chars] ignore: found? find [#"^M" #"^-" up down left right home end] event/key event/key = #"^[" ][ unless ignore [ unfocus face ] ] not ignore ]

 [3/3] from: moliad::aei::ca at: 27-Aug-2006 23:35

Re: [view] field, input filter hook! (fixed)


oops! previous example, missed delete and backspace in handled keys! fixed version follows: ;-------------------------------------------------------------------- chars: charset [#"0" - #"9" "."] key-hook: func [ face event /local ignore ][ if any [ ignore: parse to-string event/key [chars] ignore: found? find [#"^M" #"^-" up down left right home end #"^~" #"^H"] event/key event/key = #"^[" ][ unless ignore [ unfocus face ] ] not ignore ; (we must supply opposite, we tell view if its consumed?) ]