Just starting out? Need help? Post your questions and find answers here.
User avatar
DjPoke
 
Posts: 22
Joined: Sat Dec 19, 2015 5:27 pm
Location: France (Corsica)

Keyboard events for canvas and screen : focus

by DjPoke Mon Oct 14, 2019 7:27 am

Hello,

I try to give the keyboard focus to a canvas, but without success.
SetActiveGadget does nothing.
Same case for SetActiveWindow.
I must click in the canvas.
I've copied a little part of code below.
Comments are in French, but i can translate.

I also would like to sometimes open a sticky window at its front.
And open a windowed screen inside it, without loosing the focus, since i close it manually.

Any ideas ?

Code: Select all
If OpenWindow(#codeWindow, 0, 0, 800, 600, "Alien BASIC", #PB_Window_Background)
 
  If CreateMenu(#menu, WindowID(#codeWindow))
    MenuTitle("Files")
    MenuItem(1, "New")
    MenuBar()
    MenuItem(2, "Load")
    MenuItem(3, "Save")
    MenuItem(4, "Save As...")
    MenuBar()
    MenuItem(5, "Close")
    MenuBar()
    MenuItem(9, "Quit")
    MenuTitle("Run")
    MenuItem(11, "Execute")
    MenuTitle("?")
    MenuItem(21, "Help")
    MenuItem(22, "About...")
  EndIf
 
  desktop = ExamineDesktops()
  CanvasGadget(#canvas, 0, 0, DesktopWidth(desktop), DesktopHeight(desktop), #PB_Canvas_Keyboard)
         
  ; gestion des événements du menu
  BindMenuEvent(#menu, 9, @MenuCallBack())
  BindMenuEvent(#menu, 11, @MenuCallBack())
   
  ; gestion des événements de la fenêtre d'affichage
  BindEvent(#PB_Event_MoveWindow, @PositionAndSizeViewWindowCallback())
  BindEvent(#PB_Event_SizeDesktop, @PositionAndSizeViewWindowCallback())
  BindEvent(#PB_Event_CloseWindow, @CloseViewWindowCallback(), #viewWindow)
   
  ; gestion des événements des gadgets
  BindGadgetEvent(#canvas, @CanvasKeyboardHandler())
       
  ; rendu du renderer et du curseur dans le canvas
  BindEvent(#PB_Event_Timer, @ShowRendererCallback(), #codeWindow)
  AddWindowTimer(#codeWindow, #rendererTimer, 50)

EndIf
My Freewares here :
http://retro-bruno.fr/
User avatar
Peter
 
Posts: 727
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

Re: Keyboard events for canvas and screen : focus

by Peter Mon Oct 14, 2019 8:54 am

DjPoke wrote:I try to give the keyboard focus to a canvas, but without success.
SetActiveGadget does nothing.
Same case for SetActiveWindow.
I must click in the canvas.


It looks like SetActiveGadget doesn't work with the CanvasGadget.

As long as the bug is not fixed, you can use this code snippet:

Code: Select all
Protected GID
GID = GadgetID(#YourCanvasGadget)
! v_gid.gadget.focus();


Greetings ... Peter
User avatar
DjPoke
 
Posts: 22
Joined: Sat Dec 19, 2015 5:27 pm
Location: France (Corsica)

Re: Keyboard events for canvas and screen : focus

by DjPoke Mon Oct 14, 2019 10:38 am

Thanks a lot Peter. It works perfectly.
My Freewares here :
http://retro-bruno.fr/
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 9 guests