Page 1 sur 1
Canvas et keyboard
Publié : sam. 07/sept./2013 16:12
par blendman
Salut
J'essaie de déceler le release/key_up de la touche Control sur un canvas, mais ça ne marche pas.
Sauriez-vous pourquoi ?
Merci
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_DrawFocus|#PB_Canvas_Keyboard)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Select EventType()
Case #PB_EventType_KeyDown
key = GetGadgetAttribute(0,#PB_Canvas_Modifiers)
If key = #PB_Canvas_Control
Debug "down"
EndIf
Case #PB_EventType_KeyUp
key = GetGadgetAttribute(0,#PB_Canvas_Modifiers)
If key = #PB_Canvas_Control
Debug "up"
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: Canvas et keyboard
Publié : sam. 07/sept./2013 17:13
par G-Rom
Code : Tout sélectionner
key = GetGadgetAttribute(0,#PB_Canvas_Modifiers | #PB_Canvas_Control)
la doc est pas très claire.
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 7:48
par blendman
j'avais testé, mais ça ne marche pas sous windows
Du coup, j'ai du employer les grands moyens ^^.
Je teste le numéro de la touche pressée :
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_DrawFocus|#PB_Canvas_Keyboard)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Select EventType()
Case #PB_EventType_KeyDown
key = GetGadgetAttribute(0,#PB_Canvas_Modifiers)
If key = #PB_Canvas_Control
Debug "down"
EndIf
Case #PB_EventType_KeyUp
; key = GetGadgetAttribute(0,#PB_Canvas_Modifiers | #PB_Canvas_Control)
key2= GetGadgetAttribute(0,#PB_Canvas_Key)
; If key = #PB_Canvas_Control ; IF Key = 1 ; ??
If key2 = 17
Debug "up"
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Est-ce un bug ou sous windows y'a-t-il une autre manipulation ?
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 9:23
par nico
Tu peux faire ça:
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_DrawFocus|#PB_Canvas_Keyboard)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Select EventType()
Case #PB_EventType_KeyDown
key = GetGadgetAttribute(0,#PB_Canvas_Key)
If key = #VK_CONTROL
Debug "down"
EndIf
Case #PB_EventType_KeyUp
key = GetGadgetAttribute(0,#PB_Canvas_Key)
If key = #VK_CONTROL
Debug "up"
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 10:07
par Demivec
Je sais que Nico a déjà répondu à votre question, mais vous pouvez obtenir une bonne utilisation sur un include j'ai écrit pour surveiller les événements sur on canvas.
Code pour la CanvasMonitor se trouve dans le forum anglais ici:
http://www.purebasic.fr/english/viewtop ... 12&t=49468
Voici votre code avec elle comprenait:
Code : Tout sélectionner
XIncludeFile "canvasMonitor.pbi" ;ajuster chemin
initCanvasMonitor()
If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_DrawFocus|#PB_Canvas_Keyboard)
monitorCanvas(0)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
updateCanvasMonitor()
Select EventType()
Case #PB_EventType_KeyDown
key = GetGadgetAttribute(0,#PB_Canvas_Modifiers)
If key = #PB_Canvas_Control
Debug "down"
EndIf
Case #PB_EventType_KeyUp
; key = GetGadgetAttribute(0,#PB_Canvas_Modifiers | #PB_Canvas_Control)
key2= GetGadgetAttribute(0,#PB_Canvas_Key)
; If key = #PB_Canvas_Control ; IF Key = 1 ; ??
If key2 = 17
Debug "up"
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
(préparé avec l'aide de Google translate)
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 18:22
par G-Rom
mais ça ne marche pas sous windows
Win7 & linux , pas de problème (x64 les 2)
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 18:35
par falsam
G-Rom a écrit :Win7 & linux , pas de problème (x64 les 2)
G-Rom si la détection de la touche Control quand elle est enfoncée fonctionne, ce n'est pas le cas quand la touche est relâchée. (Windows 7 x64 PB 5.15 et 5.20)
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 20:01
par G-Rom
je regarderais sur mon poste demain, la gestion des évènement n'est pas correct (de mémoire).
je confirmerais pour le relâchement de la touche.
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 20:45
par Backup
comme ça , ça marche !
carre rouge appuis
carre bleu relâchement
Code : Tout sélectionner
;***********************************************
;Titre :*canvas test bouton relachement
;Auteur : Dobro
;Date :08/09/2013
;Heure :21:43:54
;Version Purebasic : PureBasic 5.11 (Windows - x86)
;Version de l'editeur :EPB V2.40
; Libairies necessaire : Aucune
;***********************************************
Enumeration
#win
#canvas
EndEnumeration
UseJPEGImageDecoder()
L=320
H=200
If OpenWindow(#win,0,0,L,H,"CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(#canvas,0,0,L,H)
Repeat
Event = WindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = #canvas
xm=GetGadgetAttribute(#canvas, #PB_Canvas_MouseX )
ym=GetGadgetAttribute(#canvas, #PB_Canvas_Mousey )
If EventType() = #PB_EventType_LeftButtonDown
StartDrawing(CanvasOutput(#canvas))
box(xm,ym,50,50,rgb(255,0,0))
StopDrawing()
elseIf EventType() = #PB_EventType_LeftButtonup
StartDrawing(CanvasOutput(#canvas))
box(xm,ym,50,50,rgb(0,0,255))
StopDrawing()
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
;
; EPB
Re: Canvas et keyboard
Publié : dim. 08/sept./2013 21:18
par G-Rom
Canvas et keyboard

Re: Canvas et keyboard
Publié : dim. 08/sept./2013 23:18
par Backup
ha oui ... pffff

.. j'approche de la 50 aine.. ceci explique cela
Re: Canvas et keyboard
Publié : lun. 09/sept./2013 7:16
par flaith
Hello, j'utilise ce systeme (exemple pour verifier si CRTL-HOME appuyée ) :
Code : Tout sélectionner
Repeat
_EventWindow = WaitWindowEvent(5)
Select _EventWindow
Case #PB_Event_Gadget
Select EventGadget()
Case #CANVAS ;<-- mon canvas
Select EventType()
Case #PB_EventType_KeyDown
; Check for CTRL, ALT, SHIFT
Canvas_Modifier = GetGadgetAttribute(#CANVAS, #PB_Canvas_Modifiers)
Select GetGadgetAttribute(#CANVAS, #PB_Canvas_Key)
Case #PB_Shortcut_Home
If Canvas_Modifier & #PB_Canvas_Control = #PB_Canvas_Control
Debug "CTRL-HOME"
EndIf
...
Re: Canvas et keyboard
Publié : lun. 09/sept./2013 8:23
par blendman
falsam a écrit :G-Rom a écrit :Win7 & linux , pas de problème (x64 les 2)
G-Rom si la détection de la touche Control quand elle est enfoncée fonctionne, ce n'est pas le cas quand la touche est relâchée. (Windows 7 x64 PB 5.15 et 5.20)
je confirme pour l'appui ça marche, mais le relâchement, sous win8 x86 ça ne marche pas

.
Re: Canvas et keyboard
Publié : mar. 10/sept./2013 8:03
par Mesa
Ça a l'air d'être un bug. Si ça n'est pas déjà fait, post le sur le forum anglais stp.
Mesa.
Re: Canvas et keyboard
Publié : mar. 10/sept./2013 13:46
par nico
Je ne crois pas que ce soit un bug, les touches Control, shift et alt sont prévues être utiliser en combinaison d'autres touches, il n'y avait pas d'utilité à recevoir l'évènement du relachement. Il faudrait plutôt faire une requête.