Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
-
blendman
- Messages : 2017
- Inscription : sam. 19/févr./2011 12:46
Message
par blendman »
salut
savez-vous comment je peux utiliser le keyboard dans une seconde fenêtre (fenêtre) ?
Il marche pour la fenêtre principale, mais pas si j'en ouvre une autre. Une idée ?
Code : Tout sélectionner
If InitSprite() And InitKeyboard()
EndIf
Procedure Openwindow2()
If OpenWindow(1,50,50,600,400,"window 2",#PB_Window_SystemMenu, WindowID(0))
Repeat
Repeat
event = WindowEvent()
If event = #PB_Event_CloseWindow
quit = 1
EndIf
Until quit >= 1 Or event = 0
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
quit = 1
EndIf
Until quit >= 1
CloseWindow(1)
EndIf
EndProcedure
If OpenWindow(0,100,100, 800,600,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
Repeat
Repeat
event = WindowEvent()
If event =#PB_Event_CloseWindow
quit = 1
EndIf
Until event = 0 Or quit = 1
ExamineKeyboard()
If KeyboardReleased(#PB_Key_LeftControl)
Ctrl = 0
ElseIf KeyboardPushed(#PB_Key_LeftControl)
Ctrl = 1
EndIf
If KeyboardReleased(#PB_Key_C)
Key_C = 1
EndIf
If ctrl = 1 And key_C = 1
Openwindow2()
key_c = 0
ctrl = 0
EndIf
FlipBuffers()
If StartDrawing(ScreenOutput())
DrawingMode(0)
txt1$ = "Ctrl : " +Str(ctrl)+" / C : "+Str(Key_C)
If Paused = #False
DrawText(20, 20, txt1$)
Else
DrawText(20, 20, txt1$)
EndIf
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape) Or quit = 1
EndIf
EndIf
-
case
- Messages : 1546
- Inscription : lun. 10/sept./2007 11:13
Message
par case »
il faut un screen ou un windowed screen pour utiliser les commande keyboard
de plus je suppose qu'il faille que le screen soit actif
Code : Tout sélectionner
; +--------------------------------------+
; | code par case @ purebasic forums |
; | case[at]moonshade.org |
; +--------------------------------------+
; | |
; | procedures d'interrogation |
; | clavier |
; | |
; +--------------------------------------+
; | |
; | PROCEDURES ET DOCUMENTATION |
; | |
; +--------------------------------------+
; | RefreshKeyboard() |
; | ***************** |
; | Récupere l'etat du clavier |
; | equivalent d'examinekeyboard() |
; | |
; | returnchar(key) |
; | *************** |
; | renvoi le caractere ascii de la |
; | touche 'key' |
; | |
; | Keydown(key) |
; | ************ |
; | renvoi 1 si la touche est enfoncee |
; | |
; | Keyup(key) |
; | ********** |
; | renvoi 1 si la touche est relachée |
; | |
; | keypushed(key) |
; | ************** |
; | renvoi 1 si la touche est appuyée |
; | mais ne l'etait pas avant |
; | |
; | keyon(key) |
; | ********** |
; | renvoi 1 si al touche est allumée |
; | numlock par exemple |
; | |
; +--------------------------------------+
InitSprite()
;+--------------------------------------+
;| BUFFERS CLAVIER |
;+--------------------------------------+
Global *buffer=AllocateMemory(256)
Global *state=AllocateMemory(256)
;+--------------------------------------+
;| CONSTANTES DEFINITION DES TOUCHES |
;+--------------------------------------+
#AltKey_windows =91
#AltKey_Shift =16
#AltKey_LeftShift =160
#AltKey_RightShift =161
#AltKey_Alt =17
#AltKey_Left_Alt =164
#AltKey_AltGr =165
#AltKey_Esc =27
#AltKey_tilde =222
#AltKey_F1 =112
#AltKey_F2 =113
#AltKey_F3 =114
#AltKey_F4 =115
#AltKey_F5 =116
#AltKey_F6 =117
#AltKey_F7 =118
#AltKey_F8 =119
#AltKey_F9 =120
#AltKey_F10 =121
#AltKey_F11 =122
#AltKey_F12 =123
#AltKey_0 =48
#AltKey_1 =49
#AltKey_2 =50
#AltKey_3 =51
#AltKey_4 =52
#AltKey_5 =53
#AltKey_6 =54
#AltKey_7 =55
#AltKey_8 =56
#AltKey_9 =57
#AltKey_parenthese =219
#AltKey_egal =187
#AltKey_backspace =8
#AltKey_windows =91
#AltKey_Tab =9
#AltKey_A =65
#AltKey_B =66
#AltKey_C =67
#AltKey_D =68
#AltKey_E =69
#AltKey_F =70
#AltKey_G =71
#AltKey_H =72
#AltKey_I =73
#AltKey_J =74
#AltKey_K =75
#AltKey_L =76
#AltKey_M =77
#AltKey_N =78
#AltKey_O =79
#AltKey_P =80
#AltKey_Q =81
#AltKey_R =82
#AltKey_S =83
#AltKey_T =84
#AltKey_U =85
#AltKey_V =86
#AltKey_W =87
#AltKey_X =88
#AltKey_Y =89
#AltKey_Z =90
#AltKey_circ =221
#AltKey_dollar =186
#AltKey_return =13
#AltKey_caps =20
#AltKey_percent =192
#AltKey_multiply =220
#AltKey_compare =226
#AltKey_space =32
#altKey_left =37
#altKey_up =38
#altKey_right =39
#altKey_down =40
#AltKey_del =46
#AltKey_pageup =33
#altKey_pagedown =34
#altKey_fin =35
#altKey_debut =36
#AltKey_inser =45
#AltKey_prtscr =44
#AltKey_pause =19
#AltKey_mute =173
#AltKey_voldwn =174
#AltKey_volup =175
#AltKey_numlock =144
#AltKey_0num =96
#AltKey_1num =97
#AltKey_2num =98
#AltKey_3num =99
#AltKey_4num =100
#AltKey_5num =101
#AltKey_6num =102
#AltKey_7num =103
#AltKey_8num =104
#AltKey_9num =105
#Altkey_minnum =109
#Altkey_addnum =107
#altKey_leftmouse =1
#altKey_rightmouse =2
#AltKey_Left_Ctrl =162
#altKey_right_Ctrl =163
#altKey_middlemouse =4 ; pas sur que la valeur soit la meme suivant les souris a tester
Procedure RefreshKeyboard() ;rafraichis l'etat du clavier
CopyMemory(*buffer,*state,256) ; sauvegarde l'etat precedent pour comparaison (keyup)
GetKeyboardState_(*buffer)
EndProcedure
Procedure.s returnchar(key) ; renvoi le caractere saisi
r.s=Space(4)
ToAscii_(key,0,*buffer,@r,0)
ProcedureReturn r
EndProcedure
Procedure Keydown(key) ; teste si une touche est enfoncée (continue)
If PeekB(*buffer+key)<0
ProcedureReturn 1
EndIf
EndProcedure
Procedure keyup(key) ; teste si une touche est lachée
If PeekB(*buffer+key)>=0 And PeekB(*state+key)<0
RefreshKeyboard() ;rafraichis le clavier pour eviter un clic fantome
ProcedureReturn 1
EndIf
EndProcedure
Procedure keypushed(key) ; teste si une touche est poussée (instant)
If PeekB(*buffer+key)<0 And PeekB(*state+key)>=0
RefreshKeyboard() ;rafraichis le clavier pour eviter un clic fantome
ProcedureReturn 1
EndIf
EndProcedure
Procedure keyon(key) ; teste si une touche est 'on' ver maj, num lock etc...
ProcedureReturn PeekB(*buffer+key) &%00000001;1
EndProcedure
Procedure Openwindow2()
If OpenWindow(1,50,50,600,400,"window 2",#PB_Window_SystemMenu, WindowID(0))
Repeat
Repeat
event = WindowEvent()
If event = #PB_Event_CloseWindow
quit = 1
EndIf
Until quit >= 1 Or event = 0
RefreshKeyboard()
If keyup(#AltKey_Esc)
quit = 1
EndIf
Until quit >= 1
CloseWindow(1)
EndIf
EndProcedure
If OpenWindow(0,100,100, 800,600,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
Repeat
Repeat
event = WindowEvent()
If event =#PB_Event_CloseWindow
quit = 1
EndIf
Until event = 0 Or quit = 1
RefreshKeyboard()
If keyup(#AltKey_Left_Ctrl)
Ctrl = 0
ElseIf Keydown(#AltKey_Left_Ctrl)
Ctrl = 1
EndIf
If keyup(#AltKey_C)
Key_C = 1
EndIf
If ctrl = 1 And key_C = 1
Openwindow2()
key_c = 0
ctrl = 0
EndIf
FlipBuffers()
If StartDrawing(ScreenOutput())
DrawingMode(0)
txt1$ = "Ctrl : " +Str(ctrl)+" / C : "+Str(Key_C)
If Paused = #False
DrawText(20, 20, txt1$)
Else
DrawText(20, 20, txt1$)
EndIf
StopDrawing()
EndIf
Until Keydown(#AltKey_Esc) Or quit = 1
EndIf
EndIf


-
Mesa
- Messages : 1126
- Inscription : mer. 14/sept./2011 16:59
Message
par Mesa »
Sans api, on peut faire comme ça:
Code : Tout sélectionner
If InitSprite() And InitKeyboard()
EndIf
Procedure Openwindow2()
If OpenWindow(1,50,50,600,400,"window 1",#PB_Window_SystemMenu, WindowID(0))
AddKeyboardShortcut(1,#PB_Shortcut_Escape, #PB_Shortcut_Escape)
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case #PB_Shortcut_Escape
quit = 1
EndSelect
EndSelect
Until quit >= 1
CloseWindow(1)
EndIf
EndProcedure
If OpenWindow(0,100,100, 800,600,"window0",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
Repeat
Repeat
event = WindowEvent()
If event =#PB_Event_CloseWindow
quit = 1
EndIf
Until event = 0 Or quit = 1
ExamineKeyboard()
If KeyboardReleased(#PB_Key_LeftControl)
Ctrl = 0
ElseIf KeyboardPushed(#PB_Key_LeftControl)
Ctrl = 1
EndIf
If KeyboardReleased(#PB_Key_C)
Key_C = 1
EndIf
If ctrl = 1 And key_C = 1
Openwindow2()
key_c = 0
ctrl = 0
EndIf
FlipBuffers()
If StartDrawing(ScreenOutput())
DrawingMode(0)
txt1$ = "Ctrl : " +Str(ctrl)+" / C : "+Str(Key_C)
If Paused = #False
DrawText(20, 20, txt1$)
Else
DrawText(20, 20, txt1$)
EndIf
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape) Or quit = 1
EndIf
EndIf
M.
-
blendman
- Messages : 2017
- Inscription : sam. 19/févr./2011 12:46
Message
par blendman »
Coucou
Merci pour vos infos.
Je suis effectivement passé par les shortcut via le menu, c'est plus simple

.