super mario 63에는 "cheat"를 입력하면 모든 것을 잠금 해제할 수 있는 창이 나온다.
wpf에서도 창에 cheat를 입력하면 이벤트가 발생하도록 할 수 있을까?
using System.Windows;
using System.Windows.Input;
namespace cheat
{
public partial class MainWindow : Window
{
private int cheatIndex = 0;
private Key[] cheatKeys = {Key.C, Key.H,Key.E,Key.A,Key.T};
public MainWindow()
{
InitializeComponent();
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == cheatKeys[cheatIndex])
{
cheatIndex++;
}
else
{
cheatIndex = 0;
}
if (cheatIndex == 5)
{
MessageBox.Show("Cheat!");
cheatIndex = 0;
}
}
}
}
할 수 있다.
맞는 키를 누를 때마다 cheatIndex를 1씩 증가시키고, 틀리면 0으로 되돌아가며, 5가 되면 이벤트를 발생시키고 0으로 되돌아가는 방식이다.
생각보다 구현이 어렵지 않았다.
'C# > WPF' 카테고리의 다른 글
RelativeSource Binding (0) | 2023.03.01 |
---|---|
DataContext Binding (0) | 2023.03.01 |
[C# WPF] Binding (0) | 2023.02.18 |
[C# WPF] 연속해서 여러 번 클릭하는 것을 방지해보자. (1) | 2023.01.20 |
[C# WPF] Ctrl Z 감지하기 (0) | 2023.01.09 |
댓글