[botta & risposta]Scoprire il tasto dal suo codice ascii

Tutorial, videotutorials ed esempi creati da noi
Rispondi
Jak
Admin
Messaggi: 12355
Iscritto il: 19/08/2009, 16:20
Specialità: Programmazione 3D
Uso: GM:Studio 2
Contatta:

[botta & risposta]Scoprire il tasto dal suo codice ascii

Messaggio da Jak »

Mi stavo facendo un sistema di scelta dei tasti da parte dell'utente quando mi sono ricordato che GM mette a disposizione funzioni per rivelare il codice ascii del tasto attualmente premuto ma non permette di ottenere una stringa che identifichi il tasto premuto. Quando scegli i tasti solitamente l'utente vuole vedere sul relativo tasto scelto "INVIO" piuttosto che tasto numero 13 o cose simili.
Visto che dovevo assolutamente fare una cosa del genere me la sono fatta da me, ho usato keybard_key con tutti i tasti della mia tastiera per scoprire l codice ascii di ogni tasto al fine di fare uno script che dal tasto premuto possa restituire una stringa che identifichi il tasto.
Ho controllato tutti i tasti presenti nella mia tastiera quindi tutti quelli standard.
Probabilmente lo inserirò anche su snippet:
Spoiler

Codice: Seleziona tutto

//scopri_tasto(numero tasto)
//restituisce la stringa identificativa del tasto

//tastierino numerico
if (argument0>=96 && argument0<=105)
{
    return "NUM "+string(argument0-96);
}
//numeri
else if (argument0>=48 && argument0<=57)
{
    return string(argument0-48);
}
//lettere
else if (argument0>=65 && argument0<=90)
{
    return chr(argument0);
}
else if (argument0>=111 && argument0<=122)
{
    return "F"+string(argument0-111);
}
//speciali
else switch (argument0)
{
    case 0: return "TAB"; break;
    case 8: return "BACKSPACE"; break;
    case 13: return "ENTER"; break;
    case 16: return "SHIFT"; break;
    case 17: return "CTRL"; break;
    case 18: return "ALT"; break;
    case 19: return "PAUSA"; break;
    case 20: return "CAPS LOCK"; break;
    case 27: return "ESC"; break;
    case 32: return "SPACE"; break;
    case 33: return "PAG SU"; break;
    case 34: return "PAG GIU"; break;
    case 35: return "FINE"; break;
    case 36: return "HOME"; break;
    case 37: return "LEFT"; break;
    case 38: return "UP"; break;
    case 39: return "RIGHT"; break;
    case 40: return "DOWN"; break;
    case 45: return "INS"; break;
    case 46: return "CANC"; break;
    case 91: return "WINDOWS"; break;
    case 93: return "MENU"; break;
    case 106: return "NUM *"; break;
    case 107: return "NUM +"; break;
    case 109: return "NUM -"; break;
    case 110: return "NUM CANC"; break;
    case 111: return "NUM /"; break;
    case 144: return "BLOCK NUM"; break;
    case 145: return "BLOCK SCOR"; break;
    case 186: return "è"; break;
    case 187: return "+"; break;
    case 188: return ","; break;
    case 189: return "-"; break;
    case 190: return "."; break;
    case 191: return "ù"; break;
    case 192: return "ò"; break;
    case 219: return "'"; break;
    case 220: return "\"; break;
    case 221: return "ì"; break;
    case 222: return "à"; break;
    default: return "TASTO "+string(argument0);
}
Se il tasto non è conosciuto ad esempio 230 dice "TASTO 230".
Se volete mettere cose come "TASTO SCONOSCIUTO" vi basterà cambiare l'ultima riga di codice(il default dello switch).
Spero vi possa essere utile :sisisi:
Ultima modifica di Jak il 27/02/2011, 18:57, modificato 1 volta in totale.
Time to feel, time to believe
Dare to see what may come of our future
Lift your head, broaden your gaze
Speak your mind and your thoughts they will follow you

Avatar utente
CaMpIoN
Membro super
Messaggi: 684
Iscritto il: 17/11/2009, 16:20
Specialità: Programmatore
Uso: GM:Studio 1.4 Master
Contatta:

Re: [botta & risposta]Scoprire il tasto dal suo codice ascii

Messaggio da CaMpIoN »

Si mettilo potrebbe essere utile, ma metti anche la funzione inversa, cioè tu scrivi BACKSPACE e lui ti da il codice tasto del backspace, potrebbe essere utile anche quello..
Giochi da me creati:
Spoiler
Immagine

Jak
Admin
Messaggi: 12355
Iscritto il: 19/08/2009, 16:20
Specialità: Programmazione 3D
Uso: GM:Studio 2
Contatta:

Re: [botta & risposta]Scoprire il tasto dal suo codice ascii

Messaggio da Jak »

Avevo dimenticato le freccette, ho editato l'openpost aggiungendole.
Comnque il procedimento inverso lo fanno le variabili vk_ e per i vk che non ci sono cè ord() quindi è inutile farlo.
Time to feel, time to believe
Dare to see what may come of our future
Lift your head, broaden your gaze
Speak your mind and your thoughts they will follow you

Avatar utente
gameplay_extreme
GMI VIP
Messaggi: 3824
Iscritto il: 13/11/2010, 16:23
Uso: GM:Studio 2
Contatta:

Re: [botta & risposta]Scoprire il tasto dal suo codice ascii

Messaggio da gameplay_extreme »

CaMpIoN ha scritto:Si mettilo potrebbe essere utile, ma metti anche la funzione inversa, cioè tu scrivi BACKSPACE e lui ti da il codice tasto del backspace, potrebbe essere utile anche quello..
il codice di backspace e contenuto nella costante vk_backspace.
Per ottenere il codice della tasto A si usa ord("A")
Per ottenere il codice del tasto 6 si usa ord("6")
Immagine
clicca sul logo qui sopra per info e download riguardo ai miei software o per sapere come si crea un videogioco!

iscriviti qui gratuitamente a GMI !
Spoiler
- Una curiosità: come mai quell' ordine ?
- Perché formava una scaletta molto carina da vedere.


"ah ah...grazie alla annotazione scientifica ti ho fregato!"
(come disse la calcolatrice al display)

Avatar utente
CaMpIoN
Membro super
Messaggi: 684
Iscritto il: 17/11/2009, 16:20
Specialità: Programmatore
Uso: GM:Studio 1.4 Master
Contatta:

Re: [botta & risposta]Scoprire il tasto dal suo codice ascii

Messaggio da CaMpIoN »

Vabbe l'avevo detto perchè non conoscevo il codice tasto della freccia home allora...
Invece ho notato che c'è, l'ho visto sul manuale.
Giochi da me creati:
Spoiler
Immagine

Rispondi

Chi c’è in linea

Visitano il forum: Nessuno e 5 ospiti