keyboard input
This commit is contained in:
9
PacticeSolution/KeyboardInputSample/App.xaml
Normal file
9
PacticeSolution/KeyboardInputSample/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="KeyboardInputSample.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:KeyboardInputSample"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
17
PacticeSolution/KeyboardInputSample/App.xaml.cs
Normal file
17
PacticeSolution/KeyboardInputSample/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace KeyboardInputSample
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
10
PacticeSolution/KeyboardInputSample/AssemblyInfo.cs
Normal file
10
PacticeSolution/KeyboardInputSample/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
13
PacticeSolution/KeyboardInputSample/MainWindow.xaml
Normal file
13
PacticeSolution/KeyboardInputSample/MainWindow.xaml
Normal file
@@ -0,0 +1,13 @@
|
||||
<Window x:Class="KeyboardInputSample.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:KeyboardInputSample"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="300" Width="400">
|
||||
<StackPanel>
|
||||
<TextBox x:Name="tbxMain" Margin="20"
|
||||
KeyDown="tbxMain_KeyDown"/>
|
||||
</StackPanel>
|
||||
</Window>
|
52
PacticeSolution/KeyboardInputSample/MainWindow.xaml.cs
Normal file
52
PacticeSolution/KeyboardInputSample/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace KeyboardInputSample
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void tbxMain_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
string msg = "";
|
||||
switch(e.Key)
|
||||
{
|
||||
case Key.O:
|
||||
msg = "O";
|
||||
break;
|
||||
case Key.LeftCtrl:
|
||||
msg = "Ctrl";
|
||||
break;
|
||||
case Key.LeftAlt:
|
||||
msg = "Alt";
|
||||
break;
|
||||
}
|
||||
|
||||
// composite keys
|
||||
if (Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.Enter))
|
||||
msg = "Alt + Enter";
|
||||
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
MessageBox.Show(msg);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user