Imaginons que j'écrive dans une variable à la manière des constantes PureBasic
Exemple:
Code : Tout sélectionner
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_S
Merci d'avance
Code : Tout sélectionner
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_S
FindString pour une variable numérique ? ^^Micoute a écrit :FindString() à tout hasard.
Code : Tout sélectionner
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_SCode : Tout sélectionner
If key & #PB_Shortcut_Control & #PB_Shortcut_Alt & #PB_Shortcut_S
EndIfCode : Tout sélectionner
  Option.i = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered | #PB_Window_TitleBar
  If Option.i & #PB_Window_SystemMenu & #PB_Window_TitleBar
    Debug 2
    
  EndIf
  
  If Option.i & #PB_Window_MinimizeGadget & #PB_Window_MinimizeGadget
    Debug 3
    
  EndIf
  
  If Option.i & #PB_Window_ScreenCentered
    Debug 4
    
  EndIf
  
  If Option.i & #PB_Window_MinimizeGadget & 1
    Debug 5
    
  EndIf
  
  If Option.i & #PB_Window_TitleBar
    Debug 6
    
  EndIfLe compilateur fait le calcul avant la compilation puisque ce sont des valeurs fixes.
Par conséquent, il est vain d'essayer des les extraire de la variable key.
Code : Tout sélectionner
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_N
If key & #PB_Shortcut_Control
    Debug "True"
Else
    Debug "False"
EndIf ; Return True
If key & #PB_Shortcut_Alt
    Debug "True"
Else
    Debug "False"
EndIf ;Return True
If key & #PB_Shortcut_Control|#PB_Shortcut_Alt
    Debug "True"
Else
    Debug "False"
EndIf ; Return True
If key & #PB_Shortcut_Control|#PB_Shortcut_Shift
    Debug "True"
Else
    Debug "False"
EndIf ; Return True (la c'est un hic)
If key & #PB_Shortcut_Shift
    Debug "True"
Else
    Debug "False"
EndIf ; Return False 
If key & #PB_Shortcut_N
    Debug "True"
Else
    Debug "False"
EndIf ; Return True 
If key & #PB_Shortcut_A
    Debug "True"
Else
    Debug "False"
EndIf ; Return True (la c'est un hic)
Code : Tout sélectionner
#CONST_A = $0001
#CONST_B = $0010
#CONST_C = $0100
#CONST_D = $1000
Var.l = #CONST_B | #CONST_D
If Var & #CONST_A
  Debug "A!"
EndIf 
If Var & #CONST_B
  Debug "B!"
EndIf 
If Var & #CONST_C
  Debug "C!"
EndIf 
If Var & #CONST_D
  Debug "D!"
EndIf 
If (Var & #CONST_B) And (Var & #CONST_D)
  Debug "B & D!"
EndIf  Code : Tout sélectionner
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_N
key$ = Str(#PB_Shortcut_Control)+"|"+Str(#PB_Shortcut_Alt)+"|"+Str(#PB_Shortcut_N)
Debug key$
If FindString(key$,Str(#PB_Shortcut_Control))
    Debug "ctrl !"
Else
    Debug "False pour ctrl"
EndIf
If FindString(key$,Str(#PB_Shortcut_Alt))
    Debug "alt !"
EndIf
If FindString(key$,Str(#PB_Shortcut_N)) 
    Debug "N !"
EndIf
If FindString(key$,Str(#PB_Shortcut_Control)) And FindString(key$,Str(#PB_Shortcut_Alt)) 
    Debug "ctrl|alt !"
EndIf
If FindString(key$,Str(#PB_Shortcut_Control)) And FindString(key$,Str(#PB_Shortcut_Shift)) 
    Debug "ctrl|alt !"
Else
    Debug "pas shift | ctrl"
EndIf
If FindString(key$,Str(#PB_Shortcut_Shift)) 
    Debug "shift Ok !"
Else
    Debug "pas shift"
EndIf
If FindString(key$,Str(#PB_Shortcut_A)) 
    Debug "A Ok !"
Else
    Debug "pas A"
EndIf
Code : Tout sélectionner
If Ctrl = 1    
    If alt = 1
        If shift = 1
            
        Else 
            
        EndIf
    Else
        
    EndIf
Else
    If alt = 1
        If shift = 1
            
        Else 
            
        EndIf
    Else
        
    EndIf
EndIfCode : Tout sélectionner
Debug "Val des constantes : "
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_N
Debug key
Debug""
Debug "Conversion en String"
key$ = Str(#PB_Shortcut_Control)+"|"+Str(#PB_Shortcut_Alt)+"|"+Str(#PB_Shortcut_N)
Debug Key$
Debug ""
Debug "Extraction"
For i = 1 To CountString(key$,"|")+1
  Debug StringField(Key$,i,"|")
Next
Haaaaaa c'est plus clair avec l'explication.microdevweb a écrit :C'est pour faire une gestion de Shortcut, je pensais cela possible... Maintenant si vous me dites que non je verrais à faire autrement.
Code : Tout sélectionner
key=#PB_Shortcut_Control|#PB_Shortcut_Alt|#PB_Shortcut_S|#PB_Shortcut_Shift
If key&#PB_Shortcut_Control:Debug "control pressé":EndIf
If key&#PB_Shortcut_Alt:Debug "Alt pressé":EndIf
If key&#PB_Shortcut_Shift:Debug "Shift pressé":EndIf
 Debug "touche : "+Chr(key) ;pas besoin de masquer car chr tronque lui-même les bits inutiles....