Hotkeys

Alright so, I'm trying to create a hotkey function on a CLR form. I don't know where to declare the hotkey so they're available at any given time while the forms open, so I added them to a timer. My problem being is that by sending a key [hotkey] it does an infinite loop. Of course it's because it's on a timer, but I else'd the statement. This is what I have, Hotkey being a timer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
void Form1::HotKeys() {
	// Checkbox 1
if (GetKeyState(VK_F1) &1)
{
	if (this->checkBox1->Checked == false)
	{
		this->checkBox1->Checked = true;
	}
	else
	{
		this->checkBox1->Checked = false;
	}
}

// Checkbox 2
if (GetKeyState(VK_F2) &1)
{
	if (this->checkBox2->Checked == false)
	{
		this->checkBox2->Checked = true;
	}
	else
	{
		this->checkBox2->Checked = false;
	}
}
// Checkbox 3
if (GetKeyState(VK_F3) &1)
{
	if (this->checkBox3->Checked == false)
	{
		this->checkBox3->Checked = true;
	}
	else
	{
		this->checkBox3->Checked = false;
	}
}
// Checkbox 4
if (GetKeyState(VK_F4) &1)
{
	if (this->checkBox4->Checked == false)
	{
		this->checkBox4->Checked = true;
	}
	else
	{
		this->checkBox4->Checked = false;
	}
}
// Checkbox 5
if (GetKeyState(VK_F5) &1)
{
	if (this->checkBox5->Checked == false)
	{
		this->checkBox5->Checked = true;
	}
	else
	{
		this->checkBox5->Checked = false;
	}
}
// Checkbox 6
if (GetKeyState(VK_F6) &1)
{
	if (this->checkBox6->Checked == false)
	{
		this->checkBox6->Checked = true;
	}
	else
	{
		this->checkBox6->Checked = false;
	}
}
// Checkbox 7
if (GetKeyState(VK_F7) &1)
{
	if (this->checkBox7->Checked == false)
	{
		this->checkBox7->Checked = true;
	}
	else
	{
		this->checkBox7->Checked = false;
	}
}
// Checkbox 8
if (GetKeyState(VK_F8) &1)
{
	if (this->checkBox8->Checked == false)
	{
		this->checkBox8->Checked = true;
	}
	else
	{
		this->checkBox8->Checked = false;
	}
}
}

void Form1::Hotkey_Tick(System::Object^  sender, System::EventArgs^  e) {
	HotKeys();
}


It checks and unchecks, the only fix I could come up with is having a timer for each function, if I just have one other timer and disable the Hotkey timer after a hotkey is sent, then I won't be able to use the hotkeys on anything else. Any suggestions?
Last edited on
Someone might be able to help, but you'll get a better response at a CLR forum or whatever mutant language the code is. This is a C++ forum.
This is C++, if the syntax didn't make it obvious...
System::Object^ sender

Under C++, this looks like an attempt to carry out the XOR operation on the (static?) variable System::Object and the variable sender, but embedded in the parameter definition of a function for some crazy reason. Is that what you meant? Or is this actually some kind of CLR and/or .NET language, and not C++?
Last edited on
closed account (o1vk4iN6)
It's microsoft's frankenstein of C++, it is not standardized. Like almost all things microsoft does, it tries pushing through doing it's own thing while the rest of the world follows the standard. Should just use .Net where it was originally intended to be, in C#.
Is there any active control besides a timer that I can create the hotkey functions on? IE;

1
2
3
4
5
6
void Control() {
if (checkBox9->Checked == true)
{
     HotKeys()(;
}
}


I've tried creating my own, though I can't make it active/live.
Last edited on
I can't really help you if your syntax is wrong, but CLR still uses the same API and I can tell you that you're better off using GetAsyncKeyState(): http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx this will tell you if the key was pressed since it was last evaluated, instead of if it is being pressed at that particular split second that the program checks it with GetKeyState().

Also the way you have it written here it looks like you're toggling the 'Checked' value every time the key is pressed. Is that what you intended to do?
Yes, though it courses into an infinite loop. I'll try AsyncKeyState now and report my results.
Topic archived. No new replies allowed.