Visual Studio | WPF > 마우스 왼쪽 클릭 + Shift (또는 Alt 키) 감지 > Keyboard.IsKeyDown | Key.LeftShift | Key.LeftAlt

운영 환경
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

처리 개요



버튼을 누를 때 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
  • 좋은 웹페이지 즐겨찾기