Console.CancelKeyPress Event occurs when Control key (CTRL) and C are pressed simultaneously (CTRL+C).
Class Sample
Public Shared Sub Main()
Dim cki As ConsoleKeyInfo
Console.Clear()
Console.TreatControlCAsInput = False
AddHandler Console.CancelKeyPress, AddressOf myHandler
While True
Console.WriteLine("CTRL+C to interrupt the read operation:")
cki = Console.ReadKey(True)
Console.WriteLine(" Key pressed: {0}" & vbCrLf, cki.Key)
If cki.Key = ConsoleKey.X Then Exit While
End While
End Sub
Protected Shared Sub myHandler(ByVal sender As Object,ByVal args As ConsoleCancelEventArgs)
Console.WriteLine(" Key pressed: {0}", args.SpecialKey)
Console.WriteLine(" Cancel property: {0}", args.Cancel)
args.Cancel = True
Console.WriteLine(" Cancel property: {0}", args.Cancel)
End Sub
End Class
Related examples in the same category