本文整理汇总了C#中System.ConsoleKeyInfo类的典型用法代码示例。如果您正苦于以下问题:C# ConsoleKeyInfo类的具体用法?C# ConsoleKeyInfo怎么用?C# ConsoleKeyInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleKeyInfo类属于System命名空间,在下文中一共展示了ConsoleKeyInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Brain brain = new Brain();
// brain.doWork();
Thread myBrainThread = new Thread(new ThreadStart(brain.doWork));
myBrainThread.Start();
ConsoleKeyInfo cki = new ConsoleKeyInfo();
do
{
Console.WriteLine("\nPress 'x' key to logout.");
while (Console.KeyAvailable == false)
Thread.Sleep(250); // Loop until input is entered.
cki = Console.ReadKey(true);
// Console.WriteLine("You pressed the '{0}' key.", cki.Key);
} while (cki.Key != ConsoleKey.X);
IPEndPoint registryEP = getEndpoint(ConfigurationManager.AppSettings["registryIP"], ConfigurationManager.AppSettings["registryPort"]);
socket.Connect(registryEP);
LogoutRequest lor = new LogoutRequest();
byte[] logoutRequestMessage = lor.Encode();
socket.Send(logoutRequestMessage, logoutRequestMessage.Length);
Console.WriteLine("You have logged out.");
}
示例2: ChangePlayerDirection
static void ChangePlayerDirection(ConsoleKeyInfo key)
{
if (key.Key == ConsoleKey.W)
firstPlayerDirection = up;
if (key.Key == ConsoleKey.A)
firstPlayerDirection = left;
if (key.Key == ConsoleKey.D)
firstPlayerDirection = right;
if (key.Key == ConsoleKey.S)
firstPlayerDirection = down;
if (key.Key == ConsoleKey.UpArrow)
secondPlayerDirection = up;
if (key.Key == ConsoleKey.LeftArrow)
secondPlayerDirection = left;
if (key.Key == ConsoleKey.RightArrow)
secondPlayerDirection = right;
if (key.Key == ConsoleKey.DownArrow)
secondPlayerDirection = down;
}
示例3: BackwardWord
/// <summary>
/// Move the cursor back to the start of the current word, or if between words,
/// the start of the previous word. Word boundaries are defined by a configurable
/// set of characters.
/// </summary>
public static void BackwardWord(ConsoleKeyInfo? key = null, object arg = null)
{
int numericArg;
if (!TryGetArgAsInt(arg, out numericArg, 1))
{
return;
}
if (numericArg < 0)
{
if (CheckIsBound(ForwardWord))
{
ForwardWord(key, -numericArg);
}
else
{
NextWord(key, -numericArg);
}
return;
}
while (numericArg-- > 0)
{
int i = _singleton.FindBackwardWordPoint(_singleton.Options.WordDelimiters);
_singleton._current = i;
_singleton.PlaceCursor();
}
}
示例4: ExchangePointAndMark
public static void ExchangePointAndMark(ConsoleKeyInfo? key = null, object arg = null)
{
var tmp = _singleton._mark;
_singleton._mark = _singleton._current;
_singleton._current = tmp;
_singleton.PlaceCursor();
}
示例5: Enqueue
public void Enqueue(ConsoleKeyInfo key)
{
lock (inputQueue)
{
inputQueue.Enqueue(new HumanInputItem(key, TimeSpan.Zero, HumanInputItem.NormalDelay));
}
}
示例6: Main
static void Main(string[] args)
{
DNA firstStep = new DNA();
spark = firstStep.Strand;
bool t = false;
int iteration = 0;
ConsoleKeyInfo end = new ConsoleKeyInfo();
Console.WriteLine("AI solver will attempt equations after GA designs them");
NaturalSelection ns = new NaturalSelection();
IntellegentDesign id = new IntellegentDesign();
id.initialize();
ns.darwin(spark);
do
{
if (t==false)
{
t = true;
Root(ns,id);
}
ns.darwin(id.dueronomy(ns.vA));
Root(ns, id);
if (iteration>100||novelAns>=cap)
{
end = Console.ReadKey();
iteration = 0;
novelAns = 0;
}
iteration++;
} while (end.Key != ConsoleKey.Escape);
}
示例7: ProcessKey
protected override void ProcessKey(ConsoleKeyInfo consoleKey, InputState inputState)
{
switch(consoleKey.Key)
{
case ConsoleKey.Backspace:
if(inputState.CarrageIndex > 0)
{
inputState.Line.Remove(inputState.CarrageIndex - 1, 1);
inputState.CarrageIndex--;
Console.Write("\b");
inputState.RefreshTail(1);
}
break;
case ConsoleKey.Delete:
if(inputState.CarrageIndex < inputState.Line.Length)
{
inputState.Line.Remove(inputState.CarrageIndex, 1);
inputState.RefreshTail(1);
}
break;
default:
base.ProcessKey(consoleKey, inputState);
break;
}
}
示例8: StartReading
public void StartReading()
{
//engine.Connect();
//engine.RemoteConnect("127.0.0.1", 3008);
engine.RemoteConnect("127.0.0.1", 1726);
ConsoleKeyInfo cki = new ConsoleKeyInfo();
while (true)
{
try
{
if (Console.KeyAvailable)
{
cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.X)
{
break;
}
}
engine.ProcessEvents(1000);
}
catch (EmoEngineException e)
{
Console.WriteLine("{0}", e.ToString());
}
catch (Exception e)
{
Console.WriteLine("{0}", e.ToString());
}
}
engine.Disconnect();
}
示例9: Execute
public void Execute(ConsoleKeyInfo request)
{
foreach (Filter filter in _filters) {
filter.Execute(request);
}
_target.MovePlayer(request);
}
示例10: ConsoleLongTaskWithCancel
private static void ConsoleLongTaskWithCancel()
{
var cancelKey = new ConsoleKeyInfo('\u0011', ConsoleKey.Q, false, false, true);
ConsoleTask.StartNew
(
cancellationToken =>
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var i = 0;
while (i++ < 10)
{
if (cancellationToken.IsCancellationRequested)
{
Console.WriteLine("Cancelled");
return;
}
Console.WriteLine(stopwatch.ElapsedMilliseconds/1000);
Thread.Sleep(1000);
}
Console.WriteLine("Completed");
},
cancelKey
).Wait();
}
示例11: ProcessKey
public override bool ProcessKey(ConsoleKeyInfo key) {
if (key.Key == ConsoleKey.Enter) {
if (OnPressed != null) OnPressed (this);
return true;
}
return false;
}
示例12: ProcessCommand
private bool ProcessCommand(ConsoleKeyInfo key)
{
if (key.Modifiers.HasFlag(ConsoleModifiers.Control))
{
if (key.Key != ConsoleKey.Q) return false;
_isExit = true;
return true;
}
else if (key.Modifiers.HasFlag(ConsoleModifiers.Alt) || key.Modifiers.HasFlag(ConsoleModifiers.Shift))
{
return false;
}
if (_commands.ContainsKey(key.Key))
{
var command = _commands[key.Key];
try
{
Console.Clear();
command.Run();
}
catch (Exception e)
{
Console.Clear();
Console.WriteLine($"There were some errors while running command {command}");
e.WriteLog();
ToMainMenu();
}
return true;
}
else
return false;
}
示例13: ModoDeJogo
public ModoDeJogo()
{
cki = new ConsoleKeyInfo();
tabuleiro = new Tabuleiro();
acabou = false;
selecionarModoDeJogo();
}
示例14: ShowMenu
public static void ShowMenu()
{
Console.WriteLine("*** MENU ***");
Console.WriteLine("1. Overzicht mp3 spelers");
Console.WriteLine("2. Overzicht voorraad");
Console.WriteLine("3. Muteer voorraad");
Console.WriteLine("4. Statistieken");
Console.WriteLine("5. Toevoegen mp3 speler");
Console.WriteLine("6. ");
Console.WriteLine("7. ");
Console.WriteLine("8. Toon menu");
Console.WriteLine("9. Exit");
//Invoer wordt gelezen
ConsoleKeyInfo userinput = new ConsoleKeyInfo();
userinput = Console.ReadKey();
while (userinput.KeyChar != '9')
{
switch (userinput.KeyChar)
{
case '1':
Console.Clear();
Console.WriteLine("\rGekozen actie: {0}. Overzicht mp3 spelers\n", userinput.KeyChar);
//oude optie >> Gegevensspelers.showmp3();
Gegevenslist.overzichtzicht();
break;
case '2':
Console.Clear();
Console.WriteLine("\rGekozen actie: {0}. Overzicht voorraad\n", userinput.KeyChar);
Gegevenslist.showvoorraad();
break;
case '3':
Console.Clear();
Console.WriteLine("\rGekozen actie: {0}. Muteer voorraad\n", userinput.KeyChar);
Gegevenslist.muteren();
break;
case '4':
Console.Clear();
Console.WriteLine("\rGekozen actie: {0}. Statistieken", userinput.KeyChar);
Gegevenslist.tien();
break;
case '5':
Console.Clear();
Console.WriteLine("\rGekozen actie: {0}. Toevoegen mp3 speler", userinput.KeyChar);
Gegevenslist.mp3toevoeg();
break;
case '6':
break;
case '7':
break;
case '8':
voorraad.toonmenu();
break;
default:
break;
}
userinput = Console.ReadKey(true);
}
}
示例15: TryHandleKeyboardInput
public override bool TryHandleKeyboardInput(ConsoleKeyInfo key)
{
List<KeyboardEventHandler> potentialHandlers = new List<KeyboardEventHandler>();
if(Application.FocusManager.FocusedControl != null)
{
Application.FocusManager.FocusedControl.HandleKeyInput()
}
if(key.Modifiers.HasFlag(ConsoleModifiers.Alt))
{
}
else if (key.Modifiers.HasFlag(ConsoleModifiers.Control))
{
}
else if (key.Modifiers.HasFlag(ConsoleModifiers.Shift))
{
}
else
{
}
handlers.Peek()[KeyboardEventHandler.CreateLookupKey(key.Key, KeyboardEventMatchMode.NoModifiers)];
}