|
15 | 15 | using System.Numerics; |
16 | 16 | using Microsoft.UI.Composition; |
17 | 17 | using static ContextSwitch.Controls; |
| 18 | +using Microsoft.UI.Xaml.Controls.Primitives; |
18 | 19 |
|
19 | 20 | namespace ContextSwitch; |
20 | 21 |
|
@@ -93,24 +94,84 @@ private void FloatingTimer_Loaded(object sender, RoutedEventArgs e) |
93 | 94 | animation.Target = nameof(contentVisual.Opacity); |
94 | 95 | contentVisual.ImplicitAnimations[nameof(contentVisual.Opacity)] = animation; |
95 | 96 | } |
96 | | - |
| 97 | + bool isCtrlDown = false; |
| 98 | +#if UNPKG |
| 99 | + public const string HOTKEY_MAIN = "R-ALT"; |
| 100 | +#else |
| 101 | + public const string HOTKEY_MAIN = "R-CTRL"; |
| 102 | +#endif |
97 | 103 | private void LowLevelKeyboard_KeyPressed(KeyboardHookInfo eventDetails, KeyboardState state, ref bool Handled) |
98 | 104 | { |
| 105 | + bool isDown = state is KeyboardState.KeyDown or KeyboardState.SystemKeyDown; |
| 106 | +#if UNPKG |
| 107 | + // Use RSHIFT for debugging |
| 108 | + if (eventDetails.KeyCode == WinWrapper.Input.VirtualKey.RMENU) |
| 109 | +#else |
99 | 110 | if (eventDetails.KeyCode == WinWrapper.Input.VirtualKey.RCONTROL) |
| 111 | +#endif |
100 | 112 | { |
101 | | - bool isDown = state is KeyboardState.KeyDown or KeyboardState.SystemKeyDown; |
102 | | - if (keyReset) |
103 | | - { |
104 | | - if (isDown) Start(resetTimerDuration); |
105 | | - } |
106 | | - else |
| 113 | + Handled = true; |
| 114 | + isCtrlDown = isDown; |
| 115 | + if (!keyReset) |
107 | 116 | { |
108 | | - if (isDown) |
| 117 | + if (isCtrlDown) |
| 118 | + { |
109 | 119 | Content.Opacity = 1; |
| 120 | + ToHide = null; |
| 121 | + } |
110 | 122 | else |
111 | 123 | ToHide = DateTime.Now + TimeSpan.FromSeconds(3); |
112 | 124 | } |
113 | 125 | } |
| 126 | + if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.UP) |
| 127 | + { |
| 128 | + Handled = true; |
| 129 | + if (isDown) |
| 130 | + { |
| 131 | + if (IsTimerRunning) |
| 132 | + { |
| 133 | + endtime += TimeSpan.FromMinutes(1); |
| 134 | + TimerCallback(); |
| 135 | + } |
| 136 | + else |
| 137 | + Start(TimeSpan.FromMinutes(1)); |
| 138 | + } |
| 139 | + } |
| 140 | + if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.DOWN) |
| 141 | + { |
| 142 | + Handled = true; |
| 143 | + if (isDown && IsTimerRunning) |
| 144 | + { |
| 145 | + endtime -= TimeSpan.FromMinutes(1); |
| 146 | + TimerCallback(); |
| 147 | + } |
| 148 | + } |
| 149 | + if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.RETURN) |
| 150 | + { |
| 151 | + Handled = true; |
| 152 | + if (isDown && keyReset) |
| 153 | + { |
| 154 | + Start(resetTimerDuration); |
| 155 | + } |
| 156 | + } |
| 157 | + if (isCtrlDown && eventDetails.KeyCode == WinWrapper.Input.VirtualKey.LEFT) |
| 158 | + { |
| 159 | + Handled = true; |
| 160 | + if (isDown) |
| 161 | + { |
| 162 | + Flyout flyout = null!; |
| 163 | + flyout = new Flyout |
| 164 | + { |
| 165 | + SystemBackdrop = new MicaBackdrop(), |
| 166 | + Content = VStack(center: true, |
| 167 | + Text("Quick Actions Page Coming Soon!"), |
| 168 | + new Button { Content = "Cool!" }.WithCustomCode(x => x.Click += (_, _) => flyout.Hide()) |
| 169 | + ), |
| 170 | + ShouldConstrainToRootBounds = false |
| 171 | + }; |
| 172 | + flyout.ShowAt(Content, new() { Placement = FlyoutPlacementMode.BottomEdgeAlignedLeft}); |
| 173 | + } |
| 174 | + } |
114 | 175 | } |
115 | 176 |
|
116 | 177 | void UpdateSize() |
@@ -181,7 +242,7 @@ void TimerCallback() |
181 | 242 | Content.Opacity = 1; |
182 | 243 | keyReset = true; |
183 | 244 | ((StackPanel)Content).Children.Add( |
184 | | - HStack(center: true, Key("R-CTRL", new(0, 0, right: 5, 0)), Text("Reset Timer", TextLineBounds.Tight))); |
| 245 | + HStack(center: true, Key($"{HOTKEY_MAIN} + Enter", new(0, 0, right: 5, 0)), Text("Reset Timer", TextLineBounds.Tight))); |
185 | 246 | UpdateSize(); |
186 | 247 | } |
187 | 248 | } |
|
0 commit comments