clavier dessiné et correspondance des touches

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

clavier dessiné et correspondance des touches

Message par graph100 »

Un petit code simple mais long et fastidieux à faire :

Cet include permet de dessiner un clavier virtuel sur la zone de dessin en cours, et permet de sélectionner les touches appuyées.
J'ai réalisé ce truc pour pouvoir le réutiliser plus tard dans mes programmes pour assigner facilement les raccourcis clavier.

L'objectif à la fin est d'avoir un module complet permettant de lier des raccourcis depuis le clavier et la souris, en visualisant l'appui des touches, et les touches déjà liées, ainsi que les fonctions liées.

Un des problèmes auquel je me suis heurté est de décider sur j'utilise les handle touches des Shorcuts de PB, ou bien les handles touches spécifiques à window : #VK_*** qui permettent de distinguer bien plus finement les touches (comme les Left_Ctrl et Right_Ctrl, etc...).
Mais l'inconvénient de la 2ème solution est qu'elle n'est pas multi-OS...

Il y a un layout de clavier dans le code en datasection, mais il est possible de faire des fichiers pour en charger d'autres.

COMPILER avec l'option THREADSAFE activée !

Code : Tout sélectionner

;{######################################
; Programme : 		Virtual Keyboard Key display (for choosing binding purpose)
#VERSION = "0.01.0050"
;	
; Description : 	
;									- Draw a virtual keyboard on the current drawing surface
;									- Possibility to draw the pushed key like the exemple shows
;									
; TODOs done :
;									- Code layout
;									- Default keyboard in datasection
;									- loading custom keyboard file (you must write them ;)
;									- working exemple
;									
;	TODOs :	
;									
;									
;	Recommendation :	
;									- !!!!!  Activate Threads Supports / Activer le support des Threads !!!!!
;									
;	PB version :	
;									- Writen on 5.21 LTS x86 window
;									
; Author : graph100 alias Kriek106
;}######################################


;{ Compatibility Linux / Mac OS, I left it, even if the core program does not work well on Mac and Linux

CompilerIf Not Defined(POINT,#PB_Structure)
	Structure POINT
		x.i
		y.i
	EndStructure
CompilerEndIf

CompilerIf Not Defined(RECT,#PB_Structure)
	Structure RECT
		left.l
		top.l
		right.l
		bottom.l
	EndStructure
CompilerEndIf

CompilerIf Not Defined(Red,#PB_Constant)
	#Red = $0000FF
CompilerEndIf

CompilerIf Not Defined(White,#PB_Constant)
	#White = $FFFFFF
CompilerEndIf


;}


;{ structure


Structure KD_key_text
	text.s
	
	pos.POINT
	
	taille.d
EndStructure

Structure KD_Key
	rayon.l
	
	Key.RECT
	Name.s
	
	List Text.KD_key_text()
	
	ImageNum.l
	Imagepos.POINT
	
	ID.l
	
	color.l
EndStructure


Structure KD_Keyboard
	offset.POINT
	
	Map key.KD_Key()
	
	Map font.l()
EndStructure


Structure IKD_loadFont
	size.l
	*Map_elem.Long
EndStructure


;}


;{ procedure

Procedure.i KD_LoadKeyboard(Keyboard_file.s = "")
	*keyboard.KD_Keyboard = AllocateMemory(SizeOf(KD_Keyboard))
	InitializeStructure(*keyboard, KD_Keyboard)
	
	res = ReadFile(#PB_Any, Keyboard_file)
	If res	
		;{ chargement d'un fichier
		
		; le format d'un fichier est identique à la différence que tout doit être écrit en texte, suivi par des retours à la ligne
		
		*keyboard\offset\x = Val(ReadString(res))
		*keyboard\offset\y = Val(ReadString(res))
		
		Repeat
			id = Val(ReadString(res))
			
			If id = 13 And FindMapElement(*keyboard\key(), "13")
				*key.KD_Key = AddMapElement(*keyboard\key(), "13r")
			ElseIf id = 16 And FindMapElement(*keyboard\key(), "16")
				*key.KD_Key = AddMapElement(*keyboard\key(), "16r")
			ElseIf id = 17 And FindMapElement(*keyboard\key(), "17")
				*key.KD_Key = AddMapElement(*keyboard\key(), "17r")
			ElseIf id = 18 And FindMapElement(*keyboard\key(), "18")
				*key.KD_Key = AddMapElement(*keyboard\key(), "18r")
			Else
				*key.KD_Key = AddMapElement(*keyboard\key(), Str(id))
			EndIf
			
			
			*key\ID = id
			
			InitializeStructure(*key, KD_Key)
			
			*key\rayon = Val(ReadString(res))
			*key\Key\left = Val(ReadString(res))
			*key\Key\top = Val(ReadString(res))
			*key\Key\right = *key\Key\left + Val(ReadString(res))
			*key\Key\bottom = *key\Key\top + Val(ReadString(res))
			
			*key\Name = ReadString(res)
			
			nb = Val(ReadString(res))
			
			For j = 1 To nb
				AddElement(*key\Text())
				
				*key\Text()\text = ReadString(res)
				
				*key\Text()\pos\x = Val(ReadString(res))
				*key\Text()\pos\y = Val(ReadString(res))
				*key\Text()\taille = Val(ReadString(res))
				
				If FindMapElement(*keyboard\font(), Str(*key\Text()\taille)) = 0
					*keyboard\font(Str(*key\Text()\taille)) = LoadFont(#PB_Any, "Arial", *key\Text()\taille)
				EndIf
			Next
			
			Debug Loc(res)
			
		Until Eof(res)
		
		;}
		
		CloseFile(res)
	Else
		;{ chargement depuis une datasection
		
		*keyboard\offset\x = PeekL(?KD_Default_keyboard)
		*keyboard\offset\y = PeekL(?KD_Default_keyboard + 4)
		
		*pt = ?KD_Default_keyboard + 8
		
		Repeat
			If PeekL(*pt) = 13 And FindMapElement(*keyboard\key(), "13")
				*key.KD_Key = AddMapElement(*keyboard\key(), "13r")
			ElseIf PeekL(*pt) = 16 And FindMapElement(*keyboard\key(), "16")
				*key.KD_Key = AddMapElement(*keyboard\key(), "16r")
			ElseIf PeekL(*pt) = 17 And FindMapElement(*keyboard\key(), "17")
				*key.KD_Key = AddMapElement(*keyboard\key(), "17r")
			ElseIf PeekL(*pt) = 18 And FindMapElement(*keyboard\key(), "18")
				*key.KD_Key = AddMapElement(*keyboard\key(), "18r")
			Else
				*key.KD_Key = AddMapElement(*keyboard\key(), Str(PeekL(*pt)))
			EndIf
			
			
			*key\ID = PeekL(*pt)
			*pt + 4
			
			InitializeStructure(*key, KD_Key)
			
			*key\rayon = PeekL(*pt)
			*key\Key\left = PeekL(*pt + 4)
			*key\Key\top = PeekL(*pt + 8)
			*key\Key\right = *key\Key\left + PeekL(*pt + 12)
			*key\Key\bottom = *key\Key\top + PeekL(*pt + 16)
			
			*key\Name = PeekS(*pt + 20)
			
			*pt = *pt + 20 + Len(*key\Name + 1) * SizeOf(Character)
			
			nb = PeekL(*pt)
			
			*pt + 4
			For j = 1 To nb
				AddElement(*key\Text())
				
				*key\Text()\text = PeekS(*pt)
				
				*pt = *pt + Len(*key\Text()\text + 1) * SizeOf(Character)
				
				*key\Text()\pos\x = PeekL(*pt)
				*key\Text()\pos\y = PeekL(*pt + 4)
				*key\Text()\taille = PeekL(*pt + 8)
				
				If FindMapElement(*keyboard\font(), Str(*key\Text()\taille)) = 0
					*keyboard\font(Str(*key\Text()\taille)) = LoadFont(#PB_Any, "Arial", *key\Text()\taille)
				EndIf
				
				*pt + 12
			Next
			
		Until *pt >= ?KD_Default_keyboard_end
		
		;}
	EndIf
	
	ProcedureReturn *keyboard
EndProcedure


Procedure IKD_Thread_LoadFont(*adr.IKD_loadFont)
	*adr\Map_elem\l = LoadFont(#PB_Any, "Arial", *adr\size)
EndProcedure


Procedure KD_DrawKey(*keyboard.KD_Keyboard, *touche.KD_Key, *offset.POINT, scale_factor.d, Selected = #False)
	Protected left_top.POINT, x.l, y.l, font_size.l, tmp.IKD_loadFont
	
	DrawingMode(#PB_2DDrawing_Default)
	
	left_top\x = *touche\Key\left + *offset\x
	left_top\y = *touche\Key\top + *offset\y
	
	If Selected
		RoundBox((left_top\x - 8) * scale_factor, (left_top\y - 8) * scale_factor, (*touche\Key\right - *touche\Key\left + 16) * scale_factor, (*touche\Key\bottom - *touche\Key\top + 16) * scale_factor, *touche\rayon * scale_factor, *touche\rayon * scale_factor, #Red)
	EndIf
	
	RoundBox(left_top\x * scale_factor, left_top\y * scale_factor, (*touche\Key\right - *touche\Key\left) * scale_factor, (*touche\Key\bottom - *touche\Key\top) * scale_factor, *touche\rayon * scale_factor, *touche\rayon * scale_factor, *touche\color)
	
	If IsImage(*touche\ImageNum)
		DrawingMode(#PB_2DDrawing_AlphaBlend)
		
		DrawImage(ImageID(*touche\ImageNum), (*touche\Imagepos\x + left_top\x) * scale_factor, (*touche\Imagepos\y + left_top\y) * scale_factor, ImageWidth(*touche\ImageNum) * scale_factor, ImageHeight(*touche\ImageNum) * scale_factor)
		
	Else
		DrawingMode(#PB_2DDrawing_Transparent)
		
		ForEach *touche\Text()
			font_size = scale_factor * *touche\Text()\taille
			If FindMapElement(*keyboard\font(), Str(font_size)) = 0
				tmp\Map_elem = AddMapElement(*keyboard\font(), Str(font_size))
				tmp\size = font_size
				
				WaitThread(CreateThread(@IKD_Thread_LoadFont(), @tmp))
			EndIf
			
			DrawingFont(FontID(*keyboard\font()))
			
			If *touche\Text()\pos\x = -1
				x = left_top\x * scale_factor + ((*touche\Key\right - *touche\Key\left) * scale_factor - TextWidth(*touche\Text()\text)) / 2
				y = left_top\y * scale_factor + ((*touche\Key\bottom - *touche\Key\top) * scale_factor - TextHeight(*touche\Text()\text)) / 2
				
				DrawText(x, y, *touche\Text()\text, #White)
			Else
				DrawText((*touche\Text()\pos\x + left_top\x) * scale_factor, (*touche\Text()\pos\y + left_top\y) * scale_factor, *touche\Text()\text, #White)
			EndIf
		Next
	EndIf
EndProcedure


Procedure KD_DrawKeyboard(*keyboard.KD_Keyboard, scale_factor.d)
	If *keyboard = 0
		ProcedureReturn 
	EndIf
	
	ForEach *keyboard\key()
		KD_DrawKey(*keyboard, *keyboard\key(), *keyboard\offset, scale_factor)
	Next
EndProcedure

Procedure KD_DrawSelectedKeyboard(*keyboard.KD_Keyboard, scale_factor.d, Map KeyDown.l())
	If *keyboard = 0
		ProcedureReturn 
	EndIf
	
	ForEach *keyboard\key()
		If FindMapElement(KeyDown(), Str(Val(MapKey(*keyboard\key()))))
			KD_DrawKey(*keyboard, *keyboard\key(), *keyboard\offset, scale_factor, #True)
		Else
			KD_DrawKey(*keyboard, *keyboard\key(), *keyboard\offset, scale_factor)
		EndIf
	Next
EndProcedure


;}


;{ Default Keyboard DATA

DataSection
	KD_Default_keyboard:
	
	; offset : x, y
	Data.l -15, 0
	
	; Key DATA
	
	;{ echap, F1 - F12, pause, impécr, suppr
	
	; ECHAP (exemple)
	; ID
	Data.l #PB_Shortcut_Escape
	; rayon
	Data.l 10
	; Rect : left, top, rigth, bottom
	Data.l 90, 55, 105, 65
	; Name
	Data.s "Echap"
	; Text() : nb
	Data.l 1
	; element : nom, x(-1 to center text), y, size
	Data.s "echap"
	Data.l -1, 0, 22
	
	; F1
	Data.l #PB_Shortcut_F1
	Data.l 10
	Data.l 235, 55, 93, 65
	Data.s "F1"
	Data.l 1
	Data.s "F1"
	Data.l -1, 0, 15
	
	; F2
	Data.l #PB_Shortcut_F2
	Data.l 10
	Data.l 353, 55, 93, 65
	Data.s "F2"
	Data.l 1
	Data.s "F2"
	Data.l -1, 0, 15
	
	; F3
	Data.l #PB_Shortcut_F3
	Data.l 10
	Data.l 471, 55, 93, 65
	Data.s "F3"
	Data.l 1
	Data.s "F3"
	Data.l -1, 0, 15
	
	; F4
	Data.l #PB_Shortcut_F4
	Data.l 10
	Data.l 589, 55, 93, 65
	Data.s "F4"
	Data.l 1
	Data.s "F4"
	Data.l -1, 0, 15
	
	; F5
	Data.l #PB_Shortcut_F5
	Data.l 10
	Data.l 707, 55, 93, 65
	Data.s "F5"
	Data.l 1
	Data.s "F5"
	Data.l -1, 0, 15
	
	; F6
	Data.l #PB_Shortcut_F6
	Data.l 10
	Data.l 825, 55, 93, 65
	Data.s "F6"
	Data.l 1
	Data.s "F6"
	Data.l -1, 0, 15
	
	; F7
	Data.l #PB_Shortcut_F7
	Data.l 10
	Data.l 943, 55, 93, 65
	Data.s "F7"
	Data.l 1
	Data.s "F7"
	Data.l -1, 0, 15
	
	; F8
	Data.l #PB_Shortcut_F8
	Data.l 10
	Data.l 1061, 55, 93, 65
	Data.s "F8"
	Data.l 1
	Data.s "F8"
	Data.l -1, 0, 15
	
	; F9
	Data.l #PB_Shortcut_F9
	Data.l 10
	Data.l 1179, 55, 93, 65
	Data.s "F9"
	Data.l 1
	Data.s "F9"
	Data.l -1, 0, 15
	
	; F10
	Data.l #PB_Shortcut_F10
	Data.l 10
	Data.l 1297, 55, 93, 65
	Data.s "F10"
	Data.l 1
	Data.s "F10"
	Data.l -1, 0, 15
	
	; F11
	Data.l #PB_Shortcut_F11
	Data.l 10
	Data.l 1415, 55, 93, 65
	Data.s "F11"
	Data.l 1
	Data.s "F11"
	Data.l -1, 0, 15
	
	; F12
	Data.l #PB_Shortcut_F12
	Data.l 10
	Data.l 1533, 55, 93, 65
	Data.s "F12"
	Data.l 1
	Data.s "F12"
	Data.l -1, 0, 15
	
	; pause
	Data.l #PB_Shortcut_Pause
	Data.l 10
	Data.l 1651, 55, 93, 65
	Data.s "Pause"
	Data.l 1
	Data.s "pause"
	Data.l -1, 0, 18
	
	; impécr
	Data.l #PB_Shortcut_Snapshot
	Data.l 10
	Data.l 1769, 55, 93, 65
	Data.s "Imprime Ecran"
	Data.l 1
	Data.s "impécr"
	Data.l -1, 0, 18
	
	; suppr
	Data.l #PB_Shortcut_Delete
	Data.l 10
	Data.l 1887, 55, 93, 65
	Data.s "Imprime Ecran"
	Data.l 1
	Data.s "suppr"
	Data.l -1, 0, 18
	
	;}
	
	;{ ², 1 - 9, 0, ), =, backspace
	
	; ²
	Data.l 222
	Data.l 10
	Data.l 90, 155, 105, 105
	Data.s "²"
	Data.l 1
	Data.s "2"
	Data.l -1, 0, 22
	
	; &
	Data.l #PB_Shortcut_1
	Data.l 10
	Data.l 220, 155, 105, 105
	Data.s "&"
	Data.l 2
	Data.s "&"
	Data.l -1, 0, 22
	Data.s "1"
	Data.l 5, 5, 22
	
	; é
	Data.l #PB_Shortcut_2
	Data.l 10
	Data.l 350, 155, 105, 105
	Data.s "é"
	Data.l 2
	Data.s "é"
	Data.l -1, 0, 22
	Data.s "2"
	Data.l 5, 5, 22
	
	; "
	Data.l #PB_Shortcut_3
	Data.l 10
	Data.l 480, 155, 105, 105
	Data.s #DQUOTE$
	Data.l 2
	Data.s #DQUOTE$
	Data.l -1, 0, 22
	Data.s "3"
	Data.l 5, 5, 22
	
	; '
	Data.l #PB_Shortcut_4
	Data.l 10
	Data.l 610, 155, 105, 105
	Data.s "'"
	Data.l 2
	Data.s "'"
	Data.l -1, 0, 22
	Data.s "4"
	Data.l 5, 5, 22
	
	; (
	Data.l #PB_Shortcut_5
	Data.l 10
	Data.l 740, 155, 105, 105
	Data.s "("
	Data.l 2
	Data.s "("
	Data.l -1, 0, 22
	Data.s "5"
	Data.l 5, 5, 22
	
	; -
	Data.l #PB_Shortcut_6
	Data.l 10
	Data.l 870, 155, 105, 105
	Data.s "-"
	Data.l 2
	Data.s "-"
	Data.l -1, 0, 22
	Data.s "6"
	Data.l 5, 5, 22
	
	; è
	Data.l #PB_Shortcut_7
	Data.l 10
	Data.l 1000, 155, 105, 105
	Data.s "è"
	Data.l 2
	Data.s "è"
	Data.l -1, 0, 22
	Data.s "7"
	Data.l 5, 5, 22
	
	; _
	Data.l #PB_Shortcut_8
	Data.l 10
	Data.l 1130, 155, 105, 105
	Data.s "_"
	Data.l 2
	Data.s "_"
	Data.l -1, 0, 22
	Data.s "8"
	Data.l 5, 5, 22
	
	; ç
	Data.l #PB_Shortcut_9
	Data.l 10
	Data.l 1260, 155, 105, 105
	Data.s "ç"
	Data.l 2
	Data.s "ç"
	Data.l -1, 0, 22
	Data.s "9"
	Data.l 5, 5, 22
	
	; à
	Data.l #PB_Shortcut_0
	Data.l 10
	Data.l 1390, 155, 105, 105
	Data.s "à"
	Data.l 2
	Data.s "à"
	Data.l -1, 0, 22
	Data.s "0"
	Data.l 5, 5, 22
	
	; )
	Data.l 219
	Data.l 10
	Data.l 1520, 155, 105, 105
	Data.s ")"
	Data.l 2
	Data.s ")"
	Data.l -1, 0, 22
	Data.s "°"
	Data.l 5, 5, 22
	
	; =
	Data.l 187
	Data.l 10
	Data.l 1650, 155, 105, 105
	Data.s "="
	Data.l 2
	Data.s "="
	Data.l -1, 0, 22
	Data.s "+"
	Data.l 5, 5, 22
	
	; backspace
	Data.l #PB_Shortcut_Back
	Data.l 10
	Data.l 1780, 155, 200, 105
	Data.s "Delete"
	Data.l 1
	Data.s "Delete"
	Data.l -1, 0, 22
	
	;}
	
	;{ Tab, A - P, ^, $, return
	
	; tab
	Data.l #PB_Shortcut_Tab
	Data.l 10
	Data.l 90, 280, 160, 105
	Data.s "Tab"
	Data.l 1
	Data.s "Tab"
	Data.l -1, 0, 22
	
	; A
	Data.l #PB_Shortcut_A
	Data.l 10
	Data.l 280, 280, 105, 105
	Data.s "A"
	Data.l 1
	Data.s "A"
	Data.l -1, 0, 30
	
	; Z
	Data.l #PB_Shortcut_Z
	Data.l 10
	Data.l 410, 280, 105, 105
	Data.s "Z"
	Data.l 1
	Data.s "Z"
	Data.l -1, 0, 30
	
	; E
	Data.l #PB_Shortcut_E
	Data.l 10
	Data.l 540, 280, 105, 105
	Data.s "E"
	Data.l 1
	Data.s "E"
	Data.l -1, 0, 30
	
	; R
	Data.l #PB_Shortcut_R
	Data.l 10
	Data.l 670, 280, 105, 105
	Data.s "R"
	Data.l 1
	Data.s "R"
	Data.l -1, 0, 30
	
	; T
	Data.l #PB_Shortcut_T
	Data.l 10
	Data.l 800, 280, 105, 105
	Data.s "T"
	Data.l 1
	Data.s "T"
	Data.l -1, 0, 30
	
	; Y
	Data.l #PB_Shortcut_Y
	Data.l 10
	Data.l 930, 280, 105, 105
	Data.s "Y"
	Data.l 1
	Data.s "Y"
	Data.l -1, 0, 30
	
	; U
	Data.l #PB_Shortcut_U
	Data.l 10
	Data.l 1060, 280, 105, 105
	Data.s "U"
	Data.l 1
	Data.s "U"
	Data.l -1, 0, 30
	
	; I
	Data.l #PB_Shortcut_I
	Data.l 10
	Data.l 1190, 280, 105, 105
	Data.s "I"
	Data.l 1
	Data.s "I"
	Data.l -1, 0, 30
	
	; O
	Data.l #PB_Shortcut_O
	Data.l 10
	Data.l 1320, 280, 105, 105
	Data.s "O"
	Data.l 1
	Data.s "O"
	Data.l -1, 0, 30
	
	; P
	Data.l #PB_Shortcut_P
	Data.l 10
	Data.l 1450, 280, 105, 105
	Data.s "P"
	Data.l 1
	Data.s "P"
	Data.l -1, 0, 30
	
	; ^
	Data.l 221
	Data.l 10
	Data.l 1580, 280, 105, 105
	Data.s "^"
	Data.l 2
	Data.s "^"
	Data.l -1, 0, 30
	Data.s "¨"
	Data.l 5, 5, 22
	
	; $
	Data.l 186
	Data.l 10
	Data.l 1710, 280, 105, 105
	Data.s "$"
	Data.l 2
	Data.s "$"
	Data.l -1, 0, 30
	Data.s "£"
	Data.l 5, 5, 22
	
	
	; Retour à la ligne
	Data.l #PB_Shortcut_Return
	Data.l 10
	Data.l 1875, 280, 105, 210+20
	Data.s "Retour Chariot"
	Data.l 1
	Data.s "Return"
	Data.l -1, 0, 22
	
	;}
	
	;{ MAj, Q - M, ù, *
	
	; maj
	Data.l #PB_Shortcut_Capital
	Data.l 10
	Data.l 90, 405, 200, 105
	Data.s "MAJ"
	Data.l 1
	Data.s "MAJ"
	Data.l -1, 0, 22
	
	; Q
	Data.l #PB_Shortcut_Q
	Data.l 10
	Data.l 315, 405, 105, 105
	Data.s "Q"
	Data.l 1
	Data.s "Q"
	Data.l -1, 0, 30
	
	; S
	Data.l #PB_Shortcut_S
	Data.l 10
	Data.l 445, 405, 105, 105
	Data.s "S"
	Data.l 1
	Data.s "S"
	Data.l -1, 0, 30
	
	; D
	Data.l #PB_Shortcut_D
	Data.l 10
	Data.l 575, 405, 105, 105
	Data.s "D"
	Data.l 1
	Data.s "D"
	Data.l -1, 0, 30
	
	; F
	Data.l #PB_Shortcut_F
	Data.l 10
	Data.l 705, 405, 105, 105
	Data.s "F"
	Data.l 1
	Data.s "F"
	Data.l -1, 0, 30
	
	; G
	Data.l #PB_Shortcut_G
	Data.l 10
	Data.l 835, 405, 105, 105
	Data.s "G"
	Data.l 1
	Data.s "G"
	Data.l -1, 0, 30
	
	; H
	Data.l #PB_Shortcut_H
	Data.l 10
	Data.l 965, 405, 105, 105
	Data.s "H"
	Data.l 1
	Data.s "H"
	Data.l -1, 0, 30
	
	; J
	Data.l #PB_Shortcut_J
	Data.l 10
	Data.l 1095, 405, 105, 105
	Data.s "J"
	Data.l 1
	Data.s "J"
	Data.l -1, 0, 30
	
	; K
	Data.l #PB_Shortcut_K
	Data.l 10
	Data.l 1225, 405, 105, 105
	Data.s "K"
	Data.l 1
	Data.s "K"
	Data.l -1, 0, 30
	
	; L
	Data.l #PB_Shortcut_L
	Data.l 10
	Data.l 1355, 405, 105, 105
	Data.s "L"
	Data.l 1
	Data.s "L"
	Data.l -1, 0, 30
	
	; M
	Data.l #PB_Shortcut_M
	Data.l 10
	Data.l 1485, 405, 105, 105
	Data.s "M"
	Data.l 1
	Data.s "M"
	Data.l -1, 0, 30
	
	; ù
	Data.l 192
	Data.l 10
	Data.l 1615, 405, 105, 105
	Data.s "ù"
	Data.l 2
	Data.s "Ù"
	Data.l -1, 0, 22
	Data.s "%"
	Data.l 5, 5, 22
	
	; *
	Data.l 220
	Data.l 10
	Data.l 1745, 405, 105, 105
	Data.s "µ*"
	Data.l 2
	Data.s "*"
	Data.l -1, 0, 30
	Data.s "µ"
	Data.l 5, 5, 22
	
	;}
	
	;{ Left Shift, <, W, N, , ; : ! Rigth Shift
	
	; Left Shift
	Data.l 16
	Data.l 10
	Data.l 90, 530, 125, 105
	Data.s "Left Shift"
	Data.l 1
	Data.s "Shift"
	Data.l -1, 0, 22
	
	; <
	Data.l 226
	Data.l 10
	Data.l 240, 530, 105, 105
	Data.s "<"
	Data.l 2
	Data.s "<"
	Data.l -1, 0, 30
	Data.s ">"
	Data.l 5, 5, 22
	
	; W
	Data.l #PB_Shortcut_W
	Data.l 10
	Data.l 370, 530, 105, 105
	Data.s "W"
	Data.l 1
	Data.s "W"
	Data.l -1, 0, 30
	
	; X
	Data.l #PB_Shortcut_X
	Data.l 10
	Data.l 500, 530, 105, 105
	Data.s "X"
	Data.l 1
	Data.s "X"
	Data.l -1, 0, 30
	
	; C
	Data.l #PB_Shortcut_C
	Data.l 10
	Data.l 630, 530, 105, 105
	Data.s "C"
	Data.l 1
	Data.s "C"
	Data.l -1, 0, 30
	
	; V
	Data.l #PB_Shortcut_V
	Data.l 10
	Data.l 760, 530, 105, 105
	Data.s "V"
	Data.l 1
	Data.s "V"
	Data.l -1, 0, 30
	
	; B
	Data.l #PB_Shortcut_B
	Data.l 10
	Data.l 890, 530, 105, 105
	Data.s "B"
	Data.l 1
	Data.s "B"
	Data.l -1, 0, 30
	
	; N
	Data.l #PB_Shortcut_N
	Data.l 10
	Data.l 1020, 530, 105, 105
	Data.s "N"
	Data.l 1
	Data.s "N"
	Data.l -1, 0, 30
	
	; ,
	Data.l 188
	Data.l 10
	Data.l 1150, 530, 105, 105
	Data.s ","
	Data.l 2
	Data.s ","
	Data.l -1, 0, 30
	Data.s "?"
	Data.l 5, 5, 22
	
	; ;
	Data.l 190
	Data.l 10
	Data.l 1280, 530, 105, 105
	Data.s ";"
	Data.l 2
	Data.s ";"
	Data.l -1, 0, 30
	Data.s ";"
	Data.l 5, 5, 22
	
	; :
	Data.l 191
	Data.l 10
	Data.l 1410, 530, 105, 105
	Data.s ":"
	Data.l 2
	Data.s ":"
	Data.l -1, 0, 30
	Data.s ":"
	Data.l 5, 5, 22
	
	; !
	Data.l 223
	Data.l 10
	Data.l 1540, 530, 105, 105
	Data.s "!"
	Data.l 2
	Data.s "!"
	Data.l -1, 0, 30
	Data.s "!"
	Data.l 5, 5, 22
	
	; right shift
	Data.l 16
	Data.l 10
	Data.l 1670, 530, 310, 105
	Data.s "right shift"
	Data.l 1
	Data.s "Shift"
	Data.l -1, 0, 22
	
	;}
	
	;{ Left Ctrl, windows, alt, space, alt gr, menu, right ctrl
	
	; Left Ctrl
	Data.l 17
	Data.l 10
	Data.l 90, 655, 255, 105
	Data.s "Left Control"
	Data.l 1
	Data.s "Ctrl"
	Data.l -1, 0, 22
	
	; window
	Data.l #PB_Shortcut_LeftWindows
	Data.l 10
	Data.l 370, 655, 105, 105
	Data.s "Windows"
	Data.l 1
	Data.s "windows"
	Data.l -1, 0, 16
	
	; Alt
	Data.l 18
	Data.l 10
	Data.l 500, 655, 105, 105
	Data.s "Alt"
	Data.l 1
	Data.s "alt"
	Data.l -1, 0, 30
	
	; Espace
	Data.l #PB_Shortcut_Space
	Data.l 10
	Data.l 630, 655, 625, 105
	Data.s "Espace"
	Data.l 1
	Data.s " "
	Data.l -1, 0, 22
	
	; Alt gr
	Data.l 18
	Data.l 10
	Data.l 1280, 655, 105, 105
	Data.s "Alt gr"
	Data.l 1
	Data.s "alt gr"
	Data.l -1, 0, 22
	
	; menu
	Data.l 93
	Data.l 10
	Data.l 1410, 655, 105, 105
	Data.s "menu"
	Data.l 1
	Data.s "Menu"
	Data.l -1, 0, 22
	
	; right ctrl
	Data.l 17
	Data.l 10
	Data.l 1540, 655, 310, 105
	Data.s "right ctrl"
	Data.l 1
	Data.s "Ctrl"
	Data.l -1, 0, 22
	
	;}
	
	;{ Arrow Keys
	
	; left
	Data.l #PB_Shortcut_Left
	Data.l 10
	Data.l 1900, 685, 105, 105
	Data.s "left"
	Data.l 1
	Data.s "left"
	Data.l -1, 0, 20
	
	; down
	Data.l #PB_Shortcut_Down
	Data.l 10
	Data.l 2030, 685, 105, 105
	Data.s "down"
	Data.l 1
	Data.s "down"
	Data.l -1, 0, 20
	
	; right
	Data.l #PB_Shortcut_Right
	Data.l 10
	Data.l 2160, 685, 105, 105
	Data.s "right"
	Data.l 1
	Data.s "right"
	Data.l -1, 0, 20
	
	; up
	Data.l #PB_Shortcut_Up
	Data.l 10
	Data.l 2030, 560, 105, 105
	Data.s "up"
	Data.l 1
	Data.s "up"
	Data.l -1, 0, 20
	
	;}
	
	;{ Num Pad
	
	; deb
	Data.l #PB_Shortcut_Home
	Data.l 10
	Data.l 2185, 55, 105, 65
	Data.s "home"
	Data.l 1
	Data.s "home"
	Data.l -1, 0, 20
	
	; page up
	Data.l #PB_Shortcut_PageUp
	Data.l 10
	Data.l 2315, 55, 105, 65
	Data.s "Page Up"
	Data.l 1
	Data.s "Page Up"
	Data.l -1, 0, 16
	
	; page down
	Data.l #PB_Shortcut_PageDown
	Data.l 10
	Data.l 2445, 55, 105, 65
	Data.s "Page Down"
	Data.l 1
	Data.s "Page Down"
	Data.l -1, 0, 16
	
	; fin
	Data.l #PB_Shortcut_End
	Data.l 10
	Data.l 2575, 55, 105, 65
	Data.s "End"
	Data.l 1
	Data.s "End"
	Data.l -1, 0, 20
	
	
	; PavNum NumLock
	Data.l #PB_Shortcut_Numlock
	Data.l 10
	Data.l 2185, 155, 105, 105
	Data.s "num lock"
	Data.l 1
	Data.s "num lk"
	Data.l -1, 0, 20
	
	; PavNum /
	Data.l #PB_Shortcut_Divide
	Data.l 10
	Data.l 2315, 155, 105, 105
	Data.s "/"
	Data.l 1
	Data.s "/"
	Data.l -1, 0, 30
	
	; PavNum *
	Data.l #PB_Shortcut_Multiply
	Data.l 10
	Data.l 2445, 155, 105, 105
	Data.s "*"
	Data.l 1
	Data.s "*"
	Data.l -1, 0, 30
	
	; PavNum -
	Data.l #PB_Shortcut_Subtract
	Data.l 10
	Data.l 2575, 155, 105, 105
	Data.s "-"
	Data.l 1
	Data.s "-"
	Data.l -1, 0, 30
	
	
	; PavNum 7
	Data.l #PB_Shortcut_Pad7
	Data.l 10
	Data.l 2185, 280, 105, 105
	Data.s "7"
	Data.l 1
	Data.s "7"
	Data.l -1, 0, 30
	
	; PavNum 8
	Data.l #PB_Shortcut_Pad8
	Data.l 10
	Data.l 2315, 280, 105, 105
	Data.s "8"
	Data.l 1
	Data.s "8"
	Data.l -1, 0, 30
	
	; PavNum 9
	Data.l #PB_Shortcut_Pad9
	Data.l 10
	Data.l 2445, 280, 105, 105
	Data.s "9"
	Data.l 1
	Data.s "9"
	Data.l -1, 0, 30
	
	; PavNum +
	Data.l #PB_Shortcut_Add
	Data.l 10
	Data.l 2575, 280, 105, 230
	Data.s "+"
	Data.l 1
	Data.s "+"
	Data.l -1, 0, 30
	
	
	; PavNum 4
	Data.l #PB_Shortcut_Pad4
	Data.l 10
	Data.l 2185, 405, 105, 105
	Data.s "4"
	Data.l 1
	Data.s "4"
	Data.l -1, 0, 30
	
	; PavNum 5
	Data.l #PB_Shortcut_Pad5
	Data.l 10
	Data.l 2315, 405, 105, 105
	Data.s "5"
	Data.l 1
	Data.s "5"
	Data.l -1, 0, 30
	
	; PavNum 6
	Data.l #PB_Shortcut_Pad6
	Data.l 10
	Data.l 2445, 405, 105, 105
	Data.s "6"
	Data.l 1
	Data.s "6"
	Data.l -1, 0, 30
	
	
	; PavNum 1
	Data.l #PB_Shortcut_Pad1
	Data.l 10
	Data.l 2185, 530, 105, 105
	Data.s "1"
	Data.l 1
	Data.s "1"
	Data.l -1, 0, 30
	
	; PavNum 2
	Data.l #PB_Shortcut_Pad2
	Data.l 10
	Data.l 2315, 530, 105, 105
	Data.s "2"
	Data.l 1
	Data.s "2"
	Data.l -1, 0, 30
	
	; PavNum 3
	Data.l #PB_Shortcut_Pad3
	Data.l 10
	Data.l 2445, 530, 105, 105
	Data.s "3"
	Data.l 1
	Data.s "3"
	Data.l -1, 0, 30
	
	; PavNum Return
	Data.l #PB_Shortcut_Return
	Data.l 10
	Data.l 2575, 530, 105, 230
	Data.s "right return"
	Data.l 1
	Data.s "return"
	Data.l -1, 0, 22
	
	
	; PavNum 0
	Data.l #PB_Shortcut_Pad0
	Data.l 10
	Data.l 2315, 655, 105, 105
	Data.s "0"
	Data.l 1
	Data.s "0"
	Data.l -1, 0, 30
	
	; PavNum .
	Data.l #PB_Shortcut_Decimal
	Data.l 10
	Data.l 2445, 655, 105, 105
	Data.s "."
	Data.l 1
	Data.s "."
	Data.l -1, 0, 30
	;}
	
	KD_Default_keyboard_end:
EndDataSection

;}


;{ SECTION TEST

CompilerIf #PB_Compiler_IsMainFile
	
	;{ fenetre de test
	
	If OpenWindow(0, 0, 0, 1100, 550, "Test Key binding display", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
		CanvasGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), #PB_Canvas_Keyboard)
		
		RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
		
		SetActiveGadget(0)
	Else
		End
	EndIf
	
	scale_factor.d = 0.4
	DefaultFont = LoadFont(#PB_Any, "Arial", 12)
	
	;}
	
	
	*keyboard.KD_Keyboard = KD_LoadKeyboard()
	
	If StartDrawing(CanvasOutput(0))
		
		KD_DrawKeyboard(*keyboard, scale_factor)
		
		StopDrawing()
	EndIf	
	
	NewMap KeyDown.l()
	NewList Infos.s()
	
	Macro Addelement_Infos(txt)
		LastElement(Infos())
		AddElement(Infos())
		
		Infos() = txt
		
		If ListSize(Infos()) > 10
			FirstElement(Infos())
			DeleteElement(Infos())
		EndIf
	EndMacro
	
	
	;{ boucle principale
	
	Repeat	
		event = WaitWindowEvent()
		
		;{ event
		
		If event = #PB_Event_Gadget
			Select EventGadget()
				Case 0
					Select EventType()
						Case #PB_EventType_KeyDown
							key.l = GetGadgetAttribute(0, #PB_Canvas_Key)
							
								MAJ = #True
							Addelement_Infos("Down : " + Str(key))
							
							If FindMapElement(KeyDown(), Str(key)) = 0
								KeyDown(Str(key)) = key
								
							EndIf
							
							
						Case #PB_EventType_KeyUp
							key.l = GetGadgetAttribute(0, #PB_Canvas_Key)
							
								MAJ = #True
							Addelement_Infos("Up : " + Str(key))
							
							If FindMapElement(KeyDown(), Str(key))
								DeleteMapElement(KeyDown());, Str(key))
								
							EndIf
							
						Case #PB_EventType_MouseWheel
							  scale_factor = scale_factor + 0.1 * GetGadgetAttribute(0, #PB_Canvas_WheelDelta)
							  
							  If scale_factor < 0.1 : scale_factor = 0.1 : EndIf							  
							  If scale_factor > 1.5 : scale_factor = 1.5 : EndIf							  
							  
							  MAJ = #True
							  
					EndSelect
					
					
			EndSelect
		EndIf
		;}
		
		;{ maj dessin
		
		If MAJ
			MAJ = #False
			
			If StartDrawing(CanvasOutput(0))
				Box(0, 0, GadgetWidth(0), GadgetHeight(0), #White)
				
				KD_DrawSelectedKeyboard(*keyboard, scale_factor, KeyDown())
				
				DrawingMode(#PB_2DDrawing_Transparent)
				DrawingFont(FontID(DefaultFont))
				ForEach Infos()
					DrawText(30, 330 + ListIndex(Infos()) * 20, Infos(), 0)
				Next
				
				StopDrawing()
			EndIf
		EndIf
		
		;}
		
	Until event = #PB_Event_CloseWindow
	
	;}
	
	End
	
CompilerEndIf

;}

; IDE Options = PureBasic 5.21 LTS (Windows - x86)
; CursorPosition = 1349
; FirstLine = 138
; Folding = fLgAs9
; EnableThread
; EnableXP
; CompileSourceDirectory
; EnableCompileCount = 60
; EnableBuildCount = 0
; EnableExeConstant
Dernière modification par graph100 le jeu. 20/févr./2014 1:13, modifié 5 fois.
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Avatar de l’utilisateur
MLD
Messages : 1103
Inscription : jeu. 05/févr./2009 17:58
Localisation : Bretagne

Re: clavier dessiner et correspondance des touches

Message par MLD »

@ Graph100

Joli travail. Merci :lol: :lol:
poshu
Messages : 1138
Inscription : sam. 31/juil./2004 22:32

Re: clavier dessiner et correspondance des touches

Message par poshu »

çamarchepô sous linux et osx parce que POINT et RECT sont des structures de l'API Windows, pas de PureBasic. Dans le même ordre d'idée, #Red et #White sont des constantes de l'API Windows, et toujours pas de PB.

Code : Tout sélectionner

CompilerIf Not Defined(POINT,#PB_Structure)
	Structure POINT
		x.i
		y.i
	EndStructure
CompilerEndIf
	
CompilerIf Not Defined(RECT,#PB_Structure)
	Structure RECT ;Attention, j'ai pas check l'ordre de la structure; si tu fais des accès via adresse mémoire, ça peut foirer.
		Bottom.i
		Left.i
		Right.i
		Top.i
	EndStructure
CompilerEndIf

CompilerIf Not Defined(Red,#PB_Constant)
	#Red = $0000FF
CompilerEndIf

CompilerIf Not Defined(White,#PB_Constant)
	#White = $FFFFFF
CompilerEndIf
Il suffit de placer ça en début de code, et hop, apu de problème :D

Après, çamarchepô non plus parce que ligne 210: [ERROR] LoadFont() can't be called inside a StartDrawing()/StopDrawing() block.
Avatar de l’utilisateur
Droopy
Messages : 1151
Inscription : lun. 19/juil./2004 22:31

Re: clavier dessiner et correspondance des touches

Message par Droopy »

oui c'est loli
Avatar de l’utilisateur
Ar-S
Messages : 9476
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: clavier dessiner et correspondance des touches

Message par Ar-S »

En 5.21 LTS j'ai une erreur lors de la compil.
Ligne :

Code : Tout sélectionner

*adr\Map_elem\l = LoadFont(#PB_Any, "Arial", *adr\size)
ça me dit que le loadfont ne peut pas être appelée à l’intérieur d'un startdrawing/stopdrawing
J'avoue que je ne suis pas allé plus loin
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: clavier dessiner et correspondance des touches

Message par GallyHC »

Tout pareil que "Ar-S", même erreur.

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: clavier dessiner et correspondance des touches

Message par graph100 »

Merci pour vos retours.
Je vais modifier le truc spécifique de windows, j'avais oublié ça...

Sinon pour l'erreur du Loadfont, il faut activer le support des threads !!!!! (c'est indiqué bande de bonhomme !)

Linux : la partie dessin fonctionne bien, en revanche la commande PB qui retourne l'id des touches n'est vraiment pas identique à windows !
Par exemple, pour une touche A-Z, l'identifiant lors de l'appuie d'une touche n'est pas le même lors de l'évènement "Down" et "Up" !

Mac : L'affichage fonctionne, mais les touches sont trop différentes pour que le résultat soit utilisable, c'est néanmoins moins bordélique que sur Linux !

En conclusion, je vais virer la compatibilité Linux / Mac, et me concentrer sur windows... Parce que là, chaque os nécessite son propre fonctionnement.
Dommage
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

Re: clavier dessiné et correspondance des touches

Message par Mesa »

Excellent :D

Cependant, t'as laissé un "petit bug" au niveau de "scale_factor" à la ligne

Code : Tout sélectionner

N° 1429 : KD_DrawSelectedKeyboard(*keyboard, 0.4, KeyDown())
Du coup le scale_factor ne fonctionne plus quand on tape sur une touche.

M.
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: clavier dessiné et correspondance des touches

Message par graph100 »

Je n'ai pas vraiment compris ce que tu voulais souligner, mais j'ai codé la valeur de l'échelle en "dur", du coup si tu la modifies lors du premier appel du dessin, il faut aussi la modifier lors du 2nd appel, vous êtes des programmeurs non ? :D

Bon, en tout cas, maintenant vous pouvez utiliser la souris pour changer le zoom
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

Re: clavier dessiné et correspondance des touches

Message par Mesa »

Faut savoir ce que tu veux, tu veux un retour ou pas ? 8O

Je persiste à dire que c'était bien un bug car la gestion du facteur d'échelle était fait d'un mélange de variable et de constante. Forcément ça bug. :P
Mais bon, si tu ne veux pas qu'on teste tes codes...

Mesa.
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: clavier dessiné et correspondance des touches

Message par graph100 »

bien sur que qu'un retour est toujours une bonne chose :D
Simplement, je n'ai pas compris ce que tu veux me dire par "bug" ?
Le code fonctionnait sans problème sur windows, et il n'était à la base pas prévu que l'exemple permette de modifier le zoom.

C'est un include, qui doit être utilisé par le codeur.
La partie "test" est complètement séparée de la partie "code", et je ne les ais mise ensemble que pour une facilité de postage ici :wink:

Dans le "code", l'échelle est passée en paramètre avec une variable (normal), et dans le "test", je l'ai fixée avec '0.4' pour que ça rentre bien dans la fenêtre. euh, sinon, y avait rien de plus. Mais maintenant j'ai ajouté le zoom controlé par la molette de la souris (pour toi :lol: )

Sinon, des idées sur le type d'acquisition des touches à choisir ? parce que la méthode d'utiliser le getgadgetattribute() du canvasgadget() pour être multiplatforme ne fonctionne vraiment pas bien :x
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Répondre