ceobros
Member
- Joined
- Jul 8, 2022
- Messages
- 10
- Programming Experience
- Beginner
Hi, I am using the HotkeyListener Nuget package and I am trying to update a hotkey.
I have a label that displays what hotkey is being used which is F7, I added a click function to change the text.
So now the label displays "Change" and now I gave a keypress function to the form.
here is my form1 load
I also added HotKey1 as public so I can use it in the "Form1_KeyDown" event
The problem I am having is that the text in the label doesn't change to the key I pressed and the HotKey does not change either. Any help would be great.
I have a label that displays what hotkey is being used which is F7, I added a click function to change the text.
C#:
private void OnrecordPOSClick(object sender, EventArgs e) =>
recordPOS.Text = "Change";
So now the label displays "Change" and now I gave a keypress function to the form.
C#:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
var hkl = new HotkeyListener();
if (recordPOS.Text == "Change")
{
recordPOS.Text = e.KeyCode.ToString();
Keys[] keys = (Keys[])typeof(Keys).GetEnumValues();
Keys pickedKey = keys.FirstOrDefault(k => k.ToString() == recordPOS.Text);
hkl.Update(ref hotkey1, new Hotkey(pickedKey));
}
}
here is my form1 load
C#:
private void Form1_Load(object sender, EventArgs e)
{
var hkl = new HotkeyListener();
// Define a new hotkey using the Hotkey class.
// Parameters are: [modifiers], [keys].
Hotkey hotkey1 = new Hotkey(Keys.F7);
Hotkey hotkey2 = new Hotkey(Keys.F8);
Hotkey hotkey3 = new Hotkey(Keys.F9);
hkl.Add(hotkey1);
hkl.Add(hotkey2);
hkl.Add(hotkey3);
hkl.HotkeyPressed += Hkl_HotkeyPressed;
}
I also added HotKey1 as public so I can use it in the "Form1_KeyDown" event
C#:
public Hotkey hotkey1 = new Hotkey(Keys.F7);
The problem I am having is that the text in the label doesn't change to the key I pressed and the HotKey does not change either. Any help would be great.