Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions SymbolPicker/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void TestInit()
//Console.WriteLine("Oh wait, Im idiot im on release mode");


//Trace.WriteLine(KeyboardSimulator.SimulateKeyboard(0, KeyEventFlags.UNICODE, '��', true, 0));
//Trace.WriteLine(KeyboardSimulator.SimulateKeyboard(0, KeyEventFlags.UNICODE, '��', true, 0));
//Trace.WriteLine(KeyboardSimulator.SimulateKeyboard(0, KeyEventFlags.KEYUP));
}

Expand Down Expand Up @@ -75,7 +75,7 @@ private void Form1_Load(object sender, EventArgs e)
if (char.IsLetterOrDigit(Program.SettingPage.textBox_hotkey.Text[0]))
{
showHideHotKey = (Keys)Enum.Parse(typeof(Keys), Program.SettingPage.textBox_hotkey.Text.ToUpper());
if (!HotKey.API_RegisterHotKey(this.Handle, SHOWHIDEHOTKEYCODE, HotKey.control.Ctrl, showHideHotKey))
if (!HotKey.API_RegisterHotKey(this.Handle, SHOWHIDEHOTKEYCODE, HotKey.HotkeyModifier.Ctrl, showHideHotKey))
{
MessageBox.Show("Can not reg hot key!");
}
Expand Down Expand Up @@ -112,7 +112,7 @@ private Button CreateOneButton(string tag, string txt)
}
private void LoadButtons(string path, List<Symbol> lssym, List<Button> lsbtn, FlowLayoutPanel layout, string tag)
{
if (!File.Exists(path)) return; //������ �����ʹ�á� ��û����
if (!File.Exists(path)) return; //������ �����ʹ�á� ��û����
try
{
string[] linesFromTextFile = File.ReadAllLines(path);
Expand Down Expand Up @@ -144,7 +144,7 @@ private void AddButtonsToLayout(List<Button> lsbtn, FlowLayoutPanel layout)
layout.Controls.Clear();
for (int i = 0; i < lsbtn.Count; i++)
{
//Buttonû��Clone
//Buttonû��Clone
layout.Controls.Add(lsbtn[i]);
}
}
Expand Down Expand Up @@ -222,20 +222,22 @@ public static void SaveRecent()

private void Button_Click(object? sender, EventArgs e)
{
if (sender is not Button senderButton) return;

SetNoActivate(this.Handle);
ShownAndInputToTextbox((Button)sender);
ShownAndInputToTextbox(senderButton);
textBox_search.Text = "";

#region recent

#region symbols
Symbol removeS = recentSymbols.FirstOrDefault(x => x.img == ((Button)sender).Text);
Symbol? removeS = recentSymbols.FirstOrDefault(x => x.img == senderButton.Text);
if (removeS != null)
{
recentSymbols.Remove(removeS);
}

Symbol addS = allSymbols.FirstOrDefault(x => x.img == ((Button)sender).Text);
Symbol? addS = allSymbols.FirstOrDefault(x => x.img == senderButton.Text);
if (addS != null)
{
recentSymbols.Insert(0, addS);
Expand All @@ -252,15 +254,15 @@ private void Button_Click(object? sender, EventArgs e)
#endregion
#region button

Button recentBtn = recentSymbolButtons.FirstOrDefault(x => x.Text == ((Button)sender).Text);
Button? recentBtn = recentSymbolButtons.FirstOrDefault(x => x.Text == senderButton.Text);
if (recentBtn != null)
{
recentSymbolButtons.Remove(recentBtn);
recentSymbolButtons.Insert(0, recentBtn);
}
else
{
Button btn = CreateOneButton("recent", addS.img);
Button btn = CreateOneButton("recent", addS?.img ?? senderButton.Text);
recentSymbolButtons.Insert(0, btn);
}

Expand All @@ -284,7 +286,7 @@ private void ShownAndInputToTextbox(Button sender)
{
this.textBox_opt.Text = sender.Text;
//Clipboard.SetText(sender.Text);
//this.Hide(); // ���ش��� ʧȥ����
//this.Hide(); // ���ش��� ʧȥ����
Thread.Sleep(10);

//uint resultDown = KeyboardSimulator.SimulateKeyboard(0x41, KeyEventFlags.KEYDOWN);
Expand All @@ -294,19 +296,19 @@ private void ShownAndInputToTextbox(Button sender)

SimulateUnicodeInput(sender.Text);

// this.Show(); // ������ʾ����
// this.Show(); // ������ʾ����
}

public static void SimulateUnicodeInput(string text)
{
foreach (var c in text)
{
ushort unicode = (ushort)c; // ֱ��ת��Ϊ Unicode���������� U+0000 ~ U+FFFF��
ushort unicode = (ushort)c; // ֱ��ת��Ϊ Unicode���������� U+0000 ~ U+FFFF��

// ���Ͱ��������¼�
// ���Ͱ��������¼�
KeyboardSimulator.SimulateKeyboard(0, KeyEventFlags.UNICODE, unicode, true);

// ���Ͱ����ͷ��¼�
// ���Ͱ����ͷ��¼�
KeyboardSimulator.SimulateKeyboard(0, KeyEventFlags.UNICODE | KeyEventFlags.KEYUP, unicode, true);
}
}
Expand All @@ -318,13 +320,13 @@ public static void SimulateUnicodeInput(string text)

public void FilterButtons(string text)
{
//this.label_loading.Visible = true; ����Ҫ�ˣ��Ѿ��ܿ���
//this.label_loading.Visible = true; ����Ҫ�ˣ��Ѿ��ܿ���
this.Refresh();
flowLayoutPanel_all.SuspendLayout(); // ��ͣ UI ���£��������
// flowLayoutPanel.Controls.Clear(); // ����ɵİ�ť
flowLayoutPanel_all.SuspendLayout(); // ��ͣ UI ���£��������
// flowLayoutPanel.Controls.Clear(); // ����ɵİ�ť


if (string.IsNullOrEmpty(text)) //����
if (string.IsNullOrEmpty(text)) //����
{
for (int i = 0; i < allSymbols.Count; i++)
{
Expand Down Expand Up @@ -353,19 +355,19 @@ public void FilterButtons(string text)



flowLayoutPanel_all.ResumeLayout(); // �ָ� UI ����
flowLayoutPanel_all.ResumeLayout(); // �ָ� UI ����
//this.label_loading.Visible = false;
this.Refresh();
}



private CancellationTokenSource CancellationTokenSource;
private CancellationTokenSource? CancellationTokenSource;


private async void textBox_search_TextChanged(object sender, EventArgs e)
{
// ȡ��֮ǰ������
// ȡ��֮ǰ������
CancellationTokenSource?.Cancel();
CancellationTokenSource = new CancellationTokenSource();
CancellationToken token = CancellationTokenSource.Token;
Expand All @@ -375,12 +377,12 @@ private async void textBox_search_TextChanged(object sender, EventArgs e)
await Task.Delay(150, token);
if (!token.IsCancellationRequested)
{
FilterButtons(textBox_search.Text); // ִ������
FilterButtons(textBox_search.Text); // ִ������
}
}
catch (TaskCanceledException)
{
// ����ȡ���������κδ���
// ����ȡ���������κδ���
}
}

Expand Down Expand Up @@ -418,7 +420,7 @@ public static void CancleNoActivate(IntPtr hWnd)
// get
// {
// CreateParams cp = base.CreateParams;
// cp.ExStyle |= WS_EX_NOACTIVATE; // Ĭ�ϲ���ȡ����
// cp.ExStyle |= WS_EX_NOACTIVATE; // Ĭ�ϲ���ȡ����
// return cp;
// }
//}
Expand All @@ -429,7 +431,7 @@ private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
textBox_search_Leave(null, null);
textBox_search_Leave(sender, e);
this.WindowState = FormWindowState.Minimized;
}
}
Expand All @@ -441,7 +443,7 @@ private void textBox_KeyDown(object sender, KeyEventArgs e)
}
if (e.KeyCode == Keys.Escape)
{
textBox_search_Leave(null, null);
textBox_search_Leave(sender, e);
this.WindowState = FormWindowState.Minimized;
}
}
Expand Down Expand Up @@ -471,19 +473,19 @@ public static class HotKey
[DllImport("user32")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);

//���ע���ȼ���api
//���ע���ȼ���api
[DllImport("user32")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

public static bool API_RegisterHotKey(IntPtr hWnd, int id, control control, Keys vk)
public static bool API_RegisterHotKey(IntPtr hWnd, int id, HotkeyModifier control, Keys vk)
{
return RegisterHotKey(hWnd, id, (uint)control, vk);
}
public static bool API_UnregisterHotKey(IntPtr hWnd, int id)
{
return UnregisterHotKey(hWnd, id);
}
public enum control : uint
public enum HotkeyModifier : uint
{
None = 0,
Alt = 1,
Expand All @@ -494,7 +496,7 @@ public enum control : uint
}


protected override void WndProc(ref Message m) //��д������Ϣ
protected override void WndProc(ref Message m) //��д������Ϣ
{
switch (m.Msg)
{
Expand All @@ -503,7 +505,7 @@ public enum control : uint
{
case SHOWHIDEHOTKEYCODE:

label1.Focus(); //����label1�ͺ���
label1.Focus(); //����label1�ͺ���
if (this.Visible == false) //WindowState == FormWindowState.Minimized
{
// label1.Focus();
Expand All @@ -513,7 +515,7 @@ public enum control : uint
}
else
{
// label1.Focus(); //ȡ��search��Focus���ô���ʧȥ���㣬��ΪFocus�������˸��¼������û���˽�������ñ������޽��㣩
// label1.Focus(); //ȡ��search��Focus���ô���ʧȥ���㣬��ΪFocus�������˸��¼������û���˽�������ñ������޽��㣩
//this.Visible = false; //WindowState = FormWindowState.Minimized
FadeWindow(true);
}
Expand Down Expand Up @@ -581,7 +583,7 @@ private async void FadeWindow(bool fadeOut)
#region tray
private void notifyIcon_tray_Click(object sender, EventArgs e)
{
MouseEventArgs me = e as MouseEventArgs;
MouseEventArgs? me = e as MouseEventArgs;
if (me != null && me.Button == MouseButtons.Left)
{
FadeWindow(false);
Expand Down
8 changes: 4 additions & 4 deletions SymbolPicker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace SymbolPicker
{
internal static class Program
{
public static Settings SettingPage;
public static Form1 MainForm;
public static Settings SettingPage = null!;
public static Form1 MainForm = null!;

public static Mutex mutex = new Mutex(false, "Global\\_SymbolPicker_");
public const int MUTEXMESSAGE = 0x8000 + 100; //WM_APP 0x8000 ~ 0xBFFF
Expand All @@ -22,7 +22,7 @@ static void Main()
// see https://aka.ms/applicationconfiguration.

Thread.Sleep(100); //maybe restart
if (!mutex.WaitOne(500, false)) //500ms��maybe settings restart
if (!mutex.WaitOne(500, false)) //500ms��maybe settings restart
{
SendMutexMsgToWindow();
Environment.Exit(0);
Expand All @@ -39,7 +39,7 @@ static void Main()
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private static extern IntPtr FindWindow(string? lpClassName, string lpWindowName);

private static void SendMutexMsgToWindow()
{
Expand Down
1 change: 0 additions & 1 deletion SymbolPicker/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions SymbolPicker/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void LoadSettings()
MessageBox.Show($"Error reading settings: {ex.Message}. Ignoring settings...");
return;
}
Dictionary<string, object> settings;
Dictionary<string, object>? settings;
try
{
settings = JsonSerializer.Deserialize<Dictionary<string, object>>(json);
Expand Down Expand Up @@ -98,7 +98,7 @@ public void LoadSettings()
try
{
//MessageBox.Show(a.Value.ToString());
object convertedValue = Convert.ChangeType(a.Value.ToString(), item.propertyType); //a.Value.ToString() must have ToString, or it will show that the class must implement IConvertable
object? convertedValue = Convert.ChangeType(a.Value.ToString(), item.propertyType); //a.Value.ToString() must have ToString, or it will show that the class must implement IConvertable
property.SetValue(ctrl, convertedValue);
}
catch (Exception ex)
Expand Down Expand Up @@ -138,7 +138,7 @@ public void SaveSettings()
var property = winFormCtrl.GetType().GetProperty(item.propertyName);
if (property != null)
{
object o = property.GetValue(winFormCtrl);
object? o = property.GetValue(winFormCtrl);
if (o != null) settings.Add(winFormCtrl.Name, o);
// MessageBox.Show(o.ToString());
}
Expand Down
3 changes: 2 additions & 1 deletion SymbolPicker/SymbolPicker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Loading