Ejemplo n.º 1
0
        /*Functionality Added to make the calculator work with Keyboard NumberPad
         * When the correct Key is detected it will fire off the corresponding button press*/
        private void Window_KeyDownPreview(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.NumPad0:
                Zero.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad1:
                One.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad2:
                Two.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad3:
                Three.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad4:
                Four.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad5:
                Five.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad6:
                Six.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad7:
                Seven.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad8:
                Eight.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad9:
                Nine.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Add:
                Plus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Subtract:
                Minus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Multiply:
                Multiply.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Divide:
                Divide.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Enter:
                Equals.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;
            }
        }
Ejemplo n.º 2
0
        //OFF


        /*************************************************************
        *  Obsługa przycisków
        *************************************************************/
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.D1 || e.Key == Key.NumPad1)
            {
                One.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D2 || e.Key == Key.NumPad2)
            {
                Two.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D3 || e.Key == Key.NumPad3)
            {
                Three.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D4 || e.Key == Key.NumPad4)
            {
                Four.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D5 || e.Key == Key.NumPad5)
            {
                Five.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D6 || e.Key == Key.NumPad6)
            {
                Six.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D7 || e.Key == Key.NumPad7)
            {
                Seven.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D8 || e.Key == Key.NumPad8)
            {
                if (Keyboard.IsKeyDown(Key.LeftShift))
                {
                    Star.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                }
                else
                {
                    Eight.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                }
            }
            else if (e.Key == Key.D9 || e.Key == Key.NumPad9)
            {
                Nine.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D0 || e.Key == Key.NumPad0)
            {
                Zero.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }

            /**********************************************************/

            /*else if (e.Key == Key.Enter)
             * {
             *  Equals.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
             * }*/
            else if (e.Key == Key.OemComma || e.Key == Key.OemPeriod || e.Key == Key.Decimal)
            {
                Dot.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.OemMinus || e.Key == Key.Subtract)
            {
                Minus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.OemPlus || e.Key == Key.Add)
            {
                Plus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Delete)
            {
                AC.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Back)
            {
                C.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Divide || e.Key == Key.OemBackslash || e.Key == Key.OemQuestion || e.Key == Key.Oem5)
            {
                Slash.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Multiply)
            {
                Star.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.P)
            {
                MP.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Escape)
            {
                Application.Current.Shutdown();
            }
            Console.WriteLine(e.Key.ToString());
        }