Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjw24 committed Dec 26, 2024
1 parent 4e197e0 commit 0832680
Showing 1 changed file with 13 additions and 58 deletions.
71 changes: 13 additions & 58 deletions ChefKeys/ChefKeys.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Windows.Controls;
using System.Windows.Input;
using static System.Net.Mime.MediaTypeNames;

namespace ChefKeys
{
Expand All @@ -27,11 +23,7 @@ public static class ChefKeysManager
private const int VK_LSHIFT = 0xA0;
private const int VK_RSHIFT = 0xA1;
private const int VK_SHIFT = 0x10;
private const int VK_Z = 0x5A;
private const uint KEYEVENTF_KEYUP = 0x0002;
private const int VK_CONTROL = 0x11;
private const int VK_ALT = 0x12;
private const int VK_WIN = 91;

private static LowLevelKeyboardProc _proc;
private static IntPtr _hookID = IntPtr.Zero;
Expand All @@ -53,9 +45,6 @@ public static class ChefKeysManager
[DllImport("user32.dll")]
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
private static extern short GetKeyState(int keyCode);

[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(int vKey);

Check warning on line 49 in ChefKeys/ChefKeys.cs

View workflow job for this annotation

GitHub Actions / workflow

Missing XML comment for publicly visible type or member 'ChefKeysManager.GetAsyncKeyState(int)'

Check warning on line 49 in ChefKeys/ChefKeys.cs

View workflow job for this annotation

GitHub Actions / workflow

Missing XML comment for publicly visible type or member 'ChefKeysManager.GetAsyncKeyState(int)'

Expand All @@ -78,15 +67,17 @@ internal void RegisterKeyCombo(string hotkey, int vk_code, Action<string> action
if (KeyComboRecords.Any(x => x.comboRaw == hotkey))
return;

KeyComboRecords.Add(new KeyComboRecord
{
vk_code = vk_code,
vkCodeCombo0 = vkCodeCombo0,
vkCodeCombo1 = vkCodeCombo1,
vkCodeCombo2 = vkCodeCombo2,
action = action,
comboRaw = hotkey
});
KeyComboRecords
.Add(
new KeyComboRecord
{
vk_code = vk_code,
vkCodeCombo0 = vkCodeCombo0,
vkCodeCombo1 = vkCodeCombo1,
vkCodeCombo2 = vkCodeCombo2,
action = action,
comboRaw = hotkey
});

}
};
Expand Down Expand Up @@ -173,7 +164,6 @@ private bool NonRegisteredModifierKeyPressed(Dictionary<int, string> comboKeys)
}

private static readonly Dictionary<int, KeyPressActionRecord> registeredHotkeys;

private static readonly KeyPressActionRecord nonRegisteredKeyRecord;

private static bool isLWinKeyDown = false;
Expand All @@ -183,39 +173,9 @@ private bool NonRegisteredModifierKeyPressed(Dictionary<int, string> comboKeys)

static ChefKeysManager()
{
//var registeredCombos = new List<KeyComboRecord>()
//{
// new KeyComboRecord { vkCodeCombo0 = VK_LALT, comboRaw = "LAlt+Z" },
// new KeyComboRecord { vkCodeCombo0 = VK_LSHIFT, comboRaw = "LShift+Z" },
//};

//registeredHotkeys = new Dictionary<int, KeyPressActionRecord>()
//{
//{ VK_LCTRL, new KeyPressActionRecord {vk_code = VK_LCTRL, HandleKeyPress = HandleRegisteredKeyPress, vkCodeCombo0 = VK_LSHIFT, vkCodeCombo1 = VK_LALT, vkCodeCombo2 = VK_Z, isSingleKeyRegistered = true, isComboKeyRegistered = true } },
//{ 91, new KeyPressActionRecord {vk_code = 91, HandleKeyPress = HandleRegisteredKeyPress, isSingleKeyRegistered = true } },


//{ VK_Z, new KeyPressActionRecord {vk_code = VK_Z, HandleKeyPress = HandleRegisteredKeyPress, KeyComboRecords = registeredCombos, isSingleKeyRegistered = true, isComboKeyRegistered = true} }



//{ VK_LCTRL, new KeyPressActionRecord {vk_code = VK_LCTRL, HandleKeyPress = HandleRegisteredKeyPress, isSingleKeyRegistered = true } },

//};

//registeredHotkeysCombo = new Dictionary<int, KeyPressActionRecord>()
//{
// { VK_Z, new KeyPressActionRecord{ vk_code = VK_Z, HandleKeyPress = HandleRegisteredComboKeyPress, vkCodeCombo0 = VK_LSHIFT, vkCodeCombo1 = VK_LALT, vkCodeCombo2 = VK_LCTRL } },
// { VK_LCTRL, new KeyPressActionRecord{ vk_code = VK_LCTRL, HandleKeyPress = HandleRegisteredComboKeyPress, vkCodeCombo0 = VK_LALT, vkCodeCombo1 = VK_LSHIFT, vkCodeCombo2 = VK_Z } },
// { VK_LALT, new KeyPressActionRecord{ vk_code = VK_LALT, HandleKeyPress = HandleRegisteredComboKeyPress, vkCodeCombo0 = VK_LCTRL, vkCodeCombo1 = VK_LSHIFT, vkCodeCombo2 = VK_Z } },
// { VK_LSHIFT, new KeyPressActionRecord{ vk_code = VK_LSHIFT, HandleKeyPress = HandleRegisteredComboKeyPress, vkCodeCombo0 = VK_LALT, vkCodeCombo1 = VK_LCTRL, vkCodeCombo2 = VK_Z } }
//};

registeredHotkeys = new Dictionary<int, KeyPressActionRecord>();
nonRegisteredKeyRecord = new KeyPressActionRecord { vk_code = 0, HandleKeyPress = HandleNonRegisteredKeyPress };



_proc = HookCallback;
}

Expand All @@ -240,12 +200,9 @@ private static IntPtr SetHook(LowLevelKeyboardProc proc)

private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);

private static IEnumerable<String> SplitHotkeyReversed(string hotkeys) => hotkeys.Split("+", StringSplitOptions.RemoveEmptyEntries).Reverse();
private static IEnumerable<string> SplitHotkeyReversed(string hotkeys) => hotkeys.Split("+", StringSplitOptions.RemoveEmptyEntries).Reverse();

public static void RegisterHotkey(string hotkeys, Action<string> action)
{
RegisterHotkey(hotkeys, hotkeys, action);
}
public static void RegisterHotkey(string hotkeys, Action<string> action) => RegisterHotkey(hotkeys, hotkeys, action);

Check warning on line 205 in ChefKeys/ChefKeys.cs

View workflow job for this annotation

GitHub Actions / workflow

Missing XML comment for publicly visible type or member 'ChefKeysManager.RegisterHotkey(string, Action<string>)'

public static void RegisterHotkey(string hotkeys, string previousHotkey, Action<string> action)

Check warning on line 207 in ChefKeys/ChefKeys.cs

View workflow job for this annotation

GitHub Actions / workflow

Missing XML comment for publicly visible type or member 'ChefKeysManager.RegisterHotkey(string, string, Action<string>)'
{
Expand Down Expand Up @@ -471,8 +428,6 @@ private static bool HandleNonRegisteredKeyPress(IntPtr wParam, int vkCode, KeyPr
return false;
}



private static void SendLWinKeyDown()
{
_isSimulatingKeyPress = true;
Expand Down

0 comments on commit 0832680

Please sign in to comment.