Skip to content

Commit e8638f9

Browse files
authored
Merge pull request #68 from shihuaidexianyu/master
支持 OMEN 键绑定 UWP 应用和模拟按键
2 parents 8b5c83e + 0bb280b commit e8638f9

7 files changed

Lines changed: 870 additions & 247 deletions

File tree

OmenHardware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ public static void OmenKeyOn(string method) {
963963
var consumerClass = new ManagementClass(scope, new ManagementPath("CommandLineEventConsumer"), null);
964964
var consumer = consumerClass.CreateInstance();
965965
string currentPath = AppDomain.CurrentDomain.BaseDirectory;
966-
if (method == "custom" || method == "app" || method == "preset") {
966+
if (OmenKeyActions.UsesPipe(method)) {
967967
consumer["CommandLineTemplate"] = @"cmd /c echo OmenKeyTriggered > \\.\pipe\OmenSuperHubPipe";
968968
} else {
969969
consumer["CommandLineTemplate"] = @"C:\Windows\System32\schtasks.exe /run /tn ""Omen Key""";

OmenSuperHub.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
</Compile>
316316
<Compile Include="Program.Config.cs" />
317317
<Compile Include="Program.Menu.cs" />
318+
<Compile Include="Program.OmenKey.cs" />
318319
<Compile Include="Properties\AssemblyVersion.cs" />
319320
<Compile Include="Properties\AssemblyInfo.cs" />
320321
<Compile Include="Program.cs" />
@@ -414,4 +415,4 @@
414415
<ItemGroup>
415416
<Compile Include="App\GpuAppManager.cs" />
416417
</ItemGroup>
417-
</Project>
418+
</Project>

Program.Config.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ static void SaveConfig(string configName = null) {
581581
key.SetValue("CustomIcon", customIcon);
582582
key.SetValue("OmenKey", omenKey);
583583
key.SetValue("OmenKeyAppPath", omenKeyAppPath);
584+
key.SetValue("OmenKeyAppName", omenKeyAppName);
585+
key.SetValue("OmenKeyShortcut", omenKeyShortcut);
584586
key.SetValue("OmenKeyPresetCandidates", omenKeyPresetCandidates);
585587
if (hasNVIDIAGpu || hasAMDDiscreteGpu)
586588
key.SetValue("MonitorGPU", monitorGPU);
@@ -658,6 +660,12 @@ static void SaveConfig(string configName = null) {
658660
case "OmenKeyAppPath":
659661
key.SetValue("OmenKeyAppPath", omenKeyAppPath);
660662
break;
663+
case "OmenKeyAppName":
664+
key.SetValue("OmenKeyAppName", omenKeyAppName);
665+
break;
666+
case "OmenKeyShortcut":
667+
key.SetValue("OmenKeyShortcut", omenKeyShortcut);
668+
break;
661669
case "OmenKeyPresetCandidates":
662670
key.SetValue("OmenKeyPresetCandidates", omenKeyPresetCandidates);
663671
break;
@@ -1127,17 +1135,13 @@ static void RestoreConfig() {
11271135
case "dynamic": UpdateDynamicIcon(); UpdateCheckedState("customIconGroup", Strings.IconDynamic); break;
11281136
}
11291137

1130-
omenKey = (string)key.GetValue("OmenKey", "default");
1138+
omenKey = (string)key.GetValue("OmenKey", OmenKeyActions.Default);
11311139
omenKeyAppPath = (string)key.GetValue("OmenKeyAppPath", "");
1140+
omenKeyAppName = (string)key.GetValue("OmenKeyAppName", "");
1141+
omenKeyShortcut = (string)key.GetValue("OmenKeyShortcut", "");
11321142
omenKeyPresetCandidates = (string)key.GetValue("OmenKeyPresetCandidates", GetDefaultOmenKeyPresetCandidates());
11331143
GetOmenKeyPresetCandidateKeys();
1134-
switch (omenKey) {
1135-
case "default": checkFloatingTimer.Enabled = false; OmenKeyOff(); OmenKeyOn(omenKey); UpdateCheckedState("omenKeyGroup", Strings.OmenKeyDefault); break;
1136-
case "custom": checkFloatingTimer.Enabled = true; OmenKeyOff(); OmenKeyOn(omenKey); UpdateCheckedState("omenKeyGroup", Strings.OmenKeyToggle); break;
1137-
case "app": checkFloatingTimer.Enabled = true; OmenKeyOff(); OmenKeyOn(omenKey); UpdateCheckedState("omenKeyGroup", Strings.OmenKeyLaunchApp); break;
1138-
case "preset": checkFloatingTimer.Enabled = true; OmenKeyOff(); OmenKeyOn(omenKey); UpdateCheckedState("omenKeyGroup", Strings.OmenKeySwitchPreset); break;
1139-
case "none": checkFloatingTimer.Enabled = false; OmenKeyOff(); UpdateCheckedState("omenKeyGroup", Strings.OmenKeyNone); break;
1140-
}
1144+
RestoreOmenKeyAction();
11411145

11421146
textSize = (int)key.GetValue("FloatingBarSize", 40);
11431147
UpdateFloatingText();

Program.Menu.cs

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,39 +1158,35 @@ void attachRename(ToolStripMenuItem item, string presetKey) {
11581158
menu.Items.Add(floatingBarMenu);
11591159
ToolStripMenuItem omenKeyMenu = new ToolStripMenuItem(Strings.OmenKeyMenu);
11601160
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyDefault, "omenKeyGroup", (s, e) => {
1161-
omenKey = "default";
11621161
tooltipUpdateTimer.Enabled = false;
1163-
OmenKeyOff();
1164-
OmenKeyOn(omenKey);
1165-
SaveConfig("OmenKey");
1162+
ApplyOmenKeyAction(OmenKeyActions.Default);
11661163
}, true));
11671164
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyToggle, "omenKeyGroup", (s, e) => {
1168-
omenKey = "custom";
1169-
checkFloatingTimer.Enabled = true;
1170-
OmenKeyOff();
1171-
OmenKeyOn(omenKey);
1172-
SaveConfig("OmenKey");
1165+
ApplyOmenKeyAction(OmenKeyActions.Overlay);
11731166
}, false));
11741167
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeySwitchPreset, "omenKeyGroup", (s, e) => {
1175-
omenKey = "preset";
1176-
checkFloatingTimer.Enabled = true;
1177-
OmenKeyOff();
1178-
OmenKeyOn(omenKey);
1179-
SaveConfig("OmenKey");
1168+
ApplyOmenKeyAction(OmenKeyActions.Preset);
11801169
}, false));
11811170
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyLaunchApp, "omenKeyGroup", (s, e) => {
1182-
if (string.IsNullOrWhiteSpace(omenKeyAppPath) || !File.Exists(omenKeyAppPath)) {
1171+
if (!IsOmenKeyAppTargetAvailable()) {
11831172
if (!SelectOmenKeyApp()) {
11841173
skipCheckedUpdate = true;
11851174
return;
11861175
}
11871176
SaveConfig("OmenKeyAppPath");
1177+
SaveConfig("OmenKeyAppName");
11881178
}
1189-
omenKey = "app";
1190-
checkFloatingTimer.Enabled = true;
1191-
OmenKeyOff();
1192-
OmenKeyOn(omenKey);
1193-
SaveConfig("OmenKey");
1179+
ApplyOmenKeyAction(OmenKeyActions.App);
1180+
}, false));
1181+
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyShortcut, "omenKeyGroup", (s, e) => {
1182+
if (string.IsNullOrWhiteSpace(omenKeyShortcut)) {
1183+
if (!SelectOmenKeyShortcut()) {
1184+
skipCheckedUpdate = true;
1185+
return;
1186+
}
1187+
SaveConfig("OmenKeyShortcut");
1188+
}
1189+
ApplyOmenKeyAction(OmenKeyActions.Shortcut);
11941190
}, false));
11951191
omenKeyMenu.DropDownItems.Add(new ToolStripSeparator());
11961192

@@ -1245,37 +1241,50 @@ void attachRename(ToolStripMenuItem item, string presetKey) {
12451241
omenKeyMenu.DropDownItems.Add(omenKeyPresetCandidatesMenu);
12461242
omenKeyMenu.DropDownItems.Add(new ToolStripSeparator());
12471243

1248-
string appDisplayName = string.IsNullOrWhiteSpace(omenKeyAppPath)
1249-
? Strings.OmenKeyNoAppSelected
1250-
: Path.GetFileName(omenKeyAppPath);
1251-
omenKeyMenu.DropDownItems.Add(new ToolStripMenuItem($"{Strings.OmenKeyCurrentApp}: {appDisplayName}") { Enabled = false });
1252-
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeySelectApp, null, (s, e) => {
1244+
omenKeyMenu.DropDownItems.Add(new ToolStripMenuItem($"{Strings.OmenKeyCurrentApp}: {GetOmenKeyAppDisplayName()}") { Enabled = false });
1245+
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeySelectDesktopApp, null, (s, e) => {
12531246
if (!SelectOmenKeyApp()) return;
12541247
SaveConfig("OmenKeyAppPath");
1255-
omenKey = "app";
1256-
checkFloatingTimer.Enabled = true;
1257-
OmenKeyOff();
1258-
OmenKeyOn(omenKey);
1259-
SaveConfig("OmenKey");
1248+
SaveConfig("OmenKeyAppName");
1249+
ApplyOmenKeyAction(OmenKeyActions.App);
1250+
RefreshMenu();
1251+
}, false));
1252+
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeySelectUwpApp, null, (s, e) => {
1253+
if (!SelectOmenKeyUwpApp()) return;
1254+
SaveConfig("OmenKeyAppPath");
1255+
SaveConfig("OmenKeyAppName");
1256+
ApplyOmenKeyAction(OmenKeyActions.App);
12601257
RefreshMenu();
12611258
}, false));
12621259
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyClearApp, null, (s, e) => {
12631260
omenKeyAppPath = "";
1261+
omenKeyAppName = "";
12641262
SaveConfig("OmenKeyAppPath");
1265-
if (omenKey == "app") {
1266-
omenKey = "none";
1267-
checkFloatingTimer.Enabled = false;
1268-
OmenKeyOff();
1269-
SaveConfig("OmenKey");
1263+
SaveConfig("OmenKeyAppName");
1264+
if (omenKey == OmenKeyActions.App) {
1265+
ApplyOmenKeyAction(OmenKeyActions.None);
1266+
}
1267+
RefreshMenu();
1268+
}, false));
1269+
omenKeyMenu.DropDownItems.Add(new ToolStripSeparator());
1270+
omenKeyMenu.DropDownItems.Add(new ToolStripMenuItem($"{Strings.OmenKeyCurrentShortcut}: {FormatOmenKeyShortcut(omenKeyShortcut)}") { Enabled = false });
1271+
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeySetShortcut, null, (s, e) => {
1272+
if (!SelectOmenKeyShortcut()) return;
1273+
SaveConfig("OmenKeyShortcut");
1274+
ApplyOmenKeyAction(OmenKeyActions.Shortcut);
1275+
RefreshMenu();
1276+
}, false));
1277+
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyClearShortcut, null, (s, e) => {
1278+
omenKeyShortcut = "";
1279+
SaveConfig("OmenKeyShortcut");
1280+
if (omenKey == OmenKeyActions.Shortcut) {
1281+
ApplyOmenKeyAction(OmenKeyActions.None);
12701282
}
12711283
RefreshMenu();
12721284
}, false));
12731285
omenKeyMenu.DropDownItems.Add(new ToolStripSeparator());
12741286
omenKeyMenu.DropDownItems.Add(CreateMenuItem(Strings.OmenKeyNone, "omenKeyGroup", (s, e) => {
1275-
omenKey = "none";
1276-
checkFloatingTimer.Enabled = false;
1277-
OmenKeyOff();
1278-
SaveConfig("OmenKey");
1287+
ApplyOmenKeyAction(OmenKeyActions.None);
12791288
}, false));
12801289
menu.Items.Add(omenKeyMenu);
12811290

0 commit comments

Comments
 (0)