function test_space() global g; app = init_app(); g = build_GUI(app); set(g.fig, 'KeyPressFcn', @on_type); end function on_type(~,e) global g; disp (e.Key); switch e.Key case {'escape'} close(g.fig); return; end end function app = init_app() app = struct(); app.sz = [100 200]; end function g = build_GUI(app) sz = app.sz; g = struct(); g.fig = figure('Name','test spacebar', ... 'NumberTitle','off', 'Menubar','none', 'Resize','off', ... 'Position',[200 200 sz(2)*2 sz(1)+40]); end