動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
処理概要
Buttonの押下時にShiftキーまたはAltキーを検知する。
参考
プロジェクト設定
Visual Studio / WPF > WindowsアプリケーションにてSystem.Console.WriteLine()をコンソールに出力する
code
MainWindow.xaml
<Window x:Class="_171110_t1439_shiftKey.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:_171110_t1439_shiftKey"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Width="120" Height="30" Content="Return fire!" Click="Button_Click"/>
</Grid>
</Window>
MainWindow.xaml.cs
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 _171110_t1439_shiftKey
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftShift))
{
System.Console.WriteLine("PHOTON TOPEDO!");
}
else if (Keyboard.IsKeyDown(Key.LeftAlt))
{
System.Console.WriteLine("Alert: Self-destruct sequence is activated.");
}
else {
System.Console.WriteLine("photon topede");
}
}
}
}
結果
上から順番に、
- 左Shiftを押しながら
- 左Altを押しながら
- 何も押さず
技術英語
- return fire!: 「打ち返せ」
- PHOTON TOPEDE: (光子)魚雷
- Self-destruct sequence: 自爆シーケンス
検索用キーワード
(C++ Builderで使うもの)
- ssAlt
- ssShift