Keydown event doesn't work properly....

Hey guys,

I'm writing a code for simple calculator to study UWP app development.
I wanted to input number and operator through keyboard.

Here's the code:

/
1
2
3
4
5
6
7
8
9
10
/code of keydown event of number key and numeric keyboard
void App2::MainPage::NumKey_Down(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
	if ((int)e->Key >= '0' && (int)e->Key <= '9')//number key 
		txtOutput->Text += ((int)e->Key - '0').ToString();
	else if ((int)e->Key >= 96 && (int)e->Key <= 105)//numeric keypad. 96 = 0, 105 = 9
		txtOutput->Text += ((int)e->Key - 96).ToString();
	else if ((int)e->Key == 67)//'c' key for reset input
		txtOutput->Text = "";
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//code of keydown event of operator key(+,-.*,/)
void App2::MainPage::ArithKey_Down(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e)
{
	//Get the string from the display, convert it to a number, and then store it as the left operand
	leftOperand = ConvertTextToInt(txtOutput->Text);
	int Op = (int)e->Key;

	if (Op == 107)
		currentOp = ArithOp::PLUS;
	else if (Op == 109)
		currentOp = ArithOp::MINUS;
	else if (Op == 106)
		currentOp = ArithOp::TIMES;
	else if (Op == 111)
		currentOp = ArithOp::DIVIDE;

	//Clear the display
	txtOutput->Text = "";
	clearOnNextKey = false;
}

I tested these using "123+456=579" scenario.
result:
1. inputting "123" works well.
2. "+" key downs't work.

I can't find out what's wrong with the code.
If anyone pick error for me, I'd very appreciate of it.

thanks,
c00012
Last edited on
What is it? WPF or sth. else?
And did you wrap it in a document ready ?
this code is written in C++/CX.
I am afraid not many people around here you know this stuff.
Maybe try http://www.dreamincode.net/forums/
Topic archived. No new replies allowed.