-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
494 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Data; | ||
using System.Windows.Input; | ||
|
||
namespace PixiEditor.Helpers.Converters | ||
{ | ||
public class KeyToStringConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is Key key) | ||
{ | ||
return InputKeyHelpers.GetCharFromKey(key); | ||
} | ||
else if (value is ModifierKeys) | ||
{ | ||
return value.ToString(); | ||
} | ||
else | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PixiEditor.Helpers.Extensions | ||
{ | ||
public static class EnumHelpers | ||
{ | ||
public static IEnumerable<T> GetFlags<T>(this T e) | ||
where T : Enum | ||
{ | ||
return Enum.GetValues(e.GetType()).Cast<T>().Where(x => e.HasFlag(x)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
|
||
namespace PixiEditor.Helpers | ||
{ | ||
public static class InputKeyHelpers | ||
{ | ||
public static string GetCharFromKey(Key key) | ||
{ | ||
int virtualKey = KeyInterop.VirtualKeyFromKey(key); | ||
byte[] keyboardState = new byte[256]; | ||
GetKeyboardState(keyboardState); | ||
|
||
uint scanCode = MapVirtualKeyW((uint)virtualKey, MapType.MAPVK_VK_TO_VSC); | ||
StringBuilder stringBuilder = new (3); | ||
|
||
int result = ToUnicode((uint)virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0); | ||
|
||
switch (result) | ||
{ | ||
case 0: | ||
{ | ||
return key.ToString(); | ||
} | ||
|
||
case -1: | ||
{ | ||
return stringBuilder.ToString().ToUpper(); | ||
} | ||
|
||
default: | ||
{ | ||
return stringBuilder[result - 1].ToString().ToUpper(); | ||
} | ||
} | ||
} | ||
|
||
private enum MapType : uint | ||
{ | ||
/// <summary> | ||
/// The uCode parameter is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0. | ||
/// </summary> | ||
MAPVK_VK_TO_VSC = 0x0, | ||
|
||
/// <summary> | ||
/// The uCode parameter is a scan code and is translated into a virtual-key code that does not distinguish between left- and right-hand keys. If there is no translation, the function returns 0. | ||
/// </summary> | ||
MAPVK_VSC_TO_VK = 0x1, | ||
|
||
/// <summary> | ||
/// The uCode parameter is a virtual-key code and is translated into an unshifted character value in the low order word of the return value. Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0. | ||
/// </summary> | ||
MAPVK_VK_TO_CHAR = 0x2, | ||
|
||
/// <summary> | ||
/// The uCode parameter is a scan code and is translated into a virtual-key code that distinguishes between left- and right-hand keys. If there is no translation, the function returns 0. | ||
/// </summary> | ||
MAPVK_VSC_TO_VK_EX = 0x3, | ||
} | ||
|
||
[DllImport("user32.dll")] | ||
private static extern int ToUnicode( | ||
uint wVirtKey, | ||
uint wScanCode, | ||
byte[] lpKeyState, | ||
[Out, MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 4)] | ||
StringBuilder pwszBuff, | ||
int cchBuff, | ||
uint wFlags); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern bool GetKeyboardState(byte[] lpKeyState); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern uint MapVirtualKeyW(uint uCode, MapType uMapType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
PixiEditor/Models/Controllers/Shortcuts/ShortcutController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PixiEditor.Models.Controllers.Shortcuts | ||
{ | ||
public class ShortcutGroup | ||
{ | ||
/// <summary> | ||
/// Gets or sets the shortcuts in the shortcuts group. | ||
/// </summary> | ||
public ObservableCollection<Shortcut> Shortcuts { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the shortcut group. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether gets or sets the shortcut group visible in the shortcut popup. | ||
/// </summary> | ||
public bool IsVisible { get; set; } | ||
|
||
public ShortcutGroup(string name, params Shortcut[] shortcuts) | ||
{ | ||
Name = name; | ||
Shortcuts = new ObservableCollection<Shortcut>(shortcuts); | ||
IsVisible = true; | ||
} | ||
|
||
/// <param name="name">The name of the group.</param> | ||
/// <param name="shortcuts">The shortcuts that belong in the group.</param> | ||
/// <param name="isVisible">Is the group visible in the shortcut popup.</param> | ||
public ShortcutGroup(string name, bool isVisible = true, params Shortcut[] shortcuts) | ||
: this(name, shortcuts) | ||
{ | ||
IsVisible = isVisible; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.