Impedire, mentre si tiene premuto un tasto della tastiera, si produca il medesimo effetto cliccando su un altro tasto
Il caso è quello in cui si intende evitare che, mentre si tiene premuto un tasto prima che sia stato rilasciato per la produzione di un effetto mediante l'Evento "_KeyRelease()", si intende impedire che - dopo aver eventualmente premuto un altro tasto - possa produrre il medesimo effetto anch'esso con l'Evento "_KeyRelease()". [nota 1]
Mostriamo un codice per ottenere quella inibizione. In particolare i tasti della tastiera, presi in considerazione, sono il tasto della freccia a sinistra e quello della freccia a destra. L'obiettivo è quello per cui, sin tanto che si tiene premuto uno dei due tasti, premendo eventualmente l'altro, non si produce alcun effetto.
Private status As Integer Public Sub Form_KeyPress() If status > 0 Then Return status = Key.Code End Public Sub Form_KeyRelease() If Key.Code <> status Then Return Select Case Key.Code Case Key.Right Print "Freccia a destra" Case Key.Left Print "Freccia a sinistra" End Select status = 0 End
Note
[1] Vedere anche la pagina: Impedire che cliccando su un tasto della tastiera si produca più volte il medesimo effetto