1

I'm building a word lookup application that runs in system tray and when you scan a block of a few words and then press a hotkey combination like Shift + C + V for example.

However, the problem is that when I test it on my personal machine, it works fine. But when through Tester's machine, it is not possible to catch the hotkey press event.

I'm using MouseKeyHook's library.

May everyone help you

Here is my code

enum KeyModifier
{
    None = 0,
    Alt = 1,
    Control = 2,
    Shift = 4
}
public Main()
{
    System.Diagnostics.Process myProcess = System.Diagnostics.Process.GetCurrentProcess();
    myProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;

    InitializeComponent();
    this.WindowState = FormWindowState.Minimized;
    this.ShowInTaskbar = false;
    notify.Visible = true;

    this.FormBorderStyle = FormBorderStyle.None;
    this.Padding = new Padding(borderSize);
    this.panel1.BackColor = borderColor;
    this.BackColor = borderColor;

    if (File.Exists("hotkey.txt") == false)
    {
        string noidung = "Shift+F";

        File.WriteAllText("hotkey.txt", noidung);
    }

    manage = new ManageDictionary();

    conn = ConnectDB.Connect();

    ctrl = new ControlData(m_Events, data, txtSearch);

    ctrl.SubscribeGlobal();

    resetHotKey();
}


public void resetConnection()
{
    conn = ConnectDB.Connect();
}
public void resetHotKey()
{
    string[] hot;
    string key;
    this.hotkey_Events = Hook.GlobalEvents();
    if (File.Exists("hotkey.txt"))
    {
        hot = File.ReadAllLines("hotkey.txt");
        key = hot[0];
    }
    else
    {
        key = "Shift+F";
    }
    var subhotkey = Combination.FromString(key);

    Action action = () => {
        string keyword = Clipboard.GetText().Trim();
        if (keyword.Equals(""))
            return;
        try
        {
            conn.Open();
            ArrayList re;
            re = manage.findWord(conn, keyword);

            if (re.Count == 0)
            {
                Dictionary a = new Dictionary(0, "Không tìm thấy kết quả", "", "", "", "");
                re.Add(a);
                Notification noti = new Notification(re, keyword);
                Thread.Sleep(1000);
                noti.Show();
            }
            else
            {
                Notification noti = new Notification(re, keyword);
                Thread.Sleep(1000);
                noti.Show();
            }
        }
        catch (Exception)
        {
            MessageBox.Show("Kết nối thất bại");
        }
        conn.Close();
    };

    var assignment = new Dictionary<Combination, Action>
    {
        {subhotkey, action}
    };

    this.hotkey_Events.OnCombination(assignment);
    
}
burnsi
  • 6,194
  • 13
  • 17
  • 27
Quang Tran
  • 11
  • 2

0 Answers0