feat: simplify key code.
This commit is contained in:
@@ -46,18 +46,21 @@
|
|||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
FunctionContent="/"
|
FunctionContent="/"
|
||||||
|
FunctionKey="Divide"
|
||||||
NumContent="/"
|
NumContent="/"
|
||||||
NumKey="Divide" />
|
NumKey="Divide" />
|
||||||
<u:NumPadButton
|
<u:NumPadButton
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
FunctionContent="*"
|
FunctionContent="*"
|
||||||
|
FunctionKey="Multiply"
|
||||||
NumContent="*"
|
NumContent="*"
|
||||||
NumKey="Multiply" />
|
NumKey="Multiply" />
|
||||||
<u:NumPadButton
|
<u:NumPadButton
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="3"
|
Grid.Column="3"
|
||||||
FunctionContent="-"
|
FunctionContent="-"
|
||||||
|
FunctionKey="Subtract"
|
||||||
NumContent="-"
|
NumContent="-"
|
||||||
NumKey="Subtract" />
|
NumKey="Subtract" />
|
||||||
<u:NumPadButton
|
<u:NumPadButton
|
||||||
@@ -92,6 +95,7 @@
|
|||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
FunctionContent="+"
|
FunctionContent="+"
|
||||||
NumContent="+"
|
NumContent="+"
|
||||||
|
FunctionKey="Add"
|
||||||
NumKey="Add" />
|
NumKey="Add" />
|
||||||
<u:NumPadButton
|
<u:NumPadButton
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class NumPad: TemplatedControl
|
|||||||
OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions() { Buttons = DialogButton.None });
|
OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions() { Buttons = DialogButton.None });
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<Key, string> _keyInputMapping = new()
|
private static readonly Dictionary<Key, string> KeyInputMapping = new()
|
||||||
{
|
{
|
||||||
[Key.NumPad0] = "0",
|
[Key.NumPad0] = "0",
|
||||||
[Key.NumPad1] = "1",
|
[Key.NumPad1] = "1",
|
||||||
@@ -85,45 +85,25 @@ public class NumPad: TemplatedControl
|
|||||||
|
|
||||||
public void ProcessClick(object o)
|
public void ProcessClick(object o)
|
||||||
{
|
{
|
||||||
if (o is NumPadButton b)
|
if (Target is null || o is not NumPadButton b) return;
|
||||||
|
var key = (b.NumMode ? b.NumKey : b.FunctionKey)?? Key.None;
|
||||||
|
if (KeyInputMapping.TryGetValue(key, out string s))
|
||||||
{
|
{
|
||||||
if (b.NumKey is null)
|
Target.RaiseEvent(new TextInputEventArgs()
|
||||||
{
|
{
|
||||||
Target?.RaiseEvent(new KeyEventArgs()
|
Source = this,
|
||||||
{
|
RoutedEvent = TextInputEvent,
|
||||||
Source = this,
|
Text = s,
|
||||||
RoutedEvent = KeyDownEvent,
|
});
|
||||||
Key = b.FunctionKey ?? Key.None,
|
}
|
||||||
});
|
else
|
||||||
}
|
{
|
||||||
if (b is { NumMode: true, NumKey: not null })
|
Target.RaiseEvent(new KeyEventArgs()
|
||||||
{
|
{
|
||||||
Target?.RaiseEvent(new TextInputEventArgs()
|
Source = this,
|
||||||
{
|
RoutedEvent = KeyDownEvent,
|
||||||
Source = this,
|
Key = key,
|
||||||
RoutedEvent = TextInputEvent,
|
});
|
||||||
Text = _keyInputMapping.TryGetValue(b.NumKey.Value, out var text)? text:string.Empty,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (b is { NumMode: false, FunctionKey: null, NumKey: not null })
|
|
||||||
{
|
|
||||||
Target?.RaiseEvent(new TextInputEventArgs()
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
RoutedEvent = TextInputEvent,
|
|
||||||
Text = _keyInputMapping.TryGetValue(b.NumKey.Value, out var text)? text:string.Empty,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Target?.RaiseEvent(new KeyEventArgs()
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
RoutedEvent = KeyDownEvent,
|
|
||||||
Key = b.FunctionKey ?? Key.None,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user