//private void player_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        private void player_KeyDown(object sender, RawKeyInputEventArg e)
        {
            if (e.DeviceHnd != this.device)
            {
                return;
            }

            if (ctrl.keyState.ContainsKey(e.Key))
            {
                ctrl.keyState[e.Key] = true;
            }

            if (ctrl.walkKeyBinding.ContainsKey(e.Key))
            {

                if (GameManager.currGameMgr.isGaming && acceptMovement && !isMoving)
                {

                    WalkDirection dir = ctrl.walkKeyBinding[e.Key];
                    currDir = dir;
                    if (validateOneStep(dir))
                    {
                        moveOneStep(dir);
                    }
                }
            }
        }
        private void player_KeyUp(object sender, RawKeyInputEventArg e)
        {
            if (e.DeviceHnd != this.device)
            {
                return;
            }
            if (ctrl.keyState.ContainsKey(e.Key))
            {
                ctrl.keyState[e.Key] = false;
            }

            if (currOwnedBombs > 0 && e.Key == ctrl.layBombKey)
            {
                ownedBombs.Dequeue().lay();

            }
        }
        void MW_PreviewKeyUp(object sender, RawKeyInputEventArg e)
        {
            Utility.MW.mdaSe.Stop();
            Utility.MW.mdaSe.Source = new Uri("Musics/ok.mp3",UriKind.Relative);
            Utility.MW.mdaSe.Play();
            if (devices.Contains(e.DeviceHnd))
            {

                int slotIdx = devices.IndexOf(e.DeviceHnd);
                if (lockSelectedDummyPlayerIdx[slotIdx] != -1)
                {
                    switch (e.Key)
                    {
                        case Key.Right:
                            selectedDummyPlayerIdx[slotIdx] = (selectedDummyPlayerIdx[slotIdx] + 1) % playerLoaders.Count;
                            if (slotIdx == 0)
                            {
                                Utility.MW.p1_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p1_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p1_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p1_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp/100*90;
                                Utility.MW.p1_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p1_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p1_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p1_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            else if (slotIdx == 1)
                            {
                                Utility.MW.p2_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p2_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p2_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p2_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p2_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p2_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p2_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p2_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            else if (slotIdx == 2)
                            {
                                Utility.MW.p3_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p3_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p3_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p3_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p3_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p3_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p3_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p3_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            else if (slotIdx == 3)
                            {
                                Utility.MW.p4_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p4_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p4_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p4_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p4_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p4_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p4_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p4_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            break;
                        case Key.Left:
                            if (selectedDummyPlayerIdx[slotIdx] == 0)
                            {
                                selectedDummyPlayerIdx[slotIdx] = playerLoaders.Count-1;
                            }
                            else
                            {
                                selectedDummyPlayerIdx[slotIdx] = (selectedDummyPlayerIdx[slotIdx] - 1) % playerLoaders.Count;
                            }

                            if (slotIdx == 0)
                            {
                                Utility.MW.p1_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p1_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p1_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p1_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p1_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p1_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p1_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p1_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            else if (slotIdx == 1)
                            {
                                Utility.MW.p2_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p2_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p2_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p2_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p2_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p2_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p2_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p2_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            else if (slotIdx == 2)
                            {
                                Utility.MW.p3_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p3_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p3_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p3_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p3_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p3_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p3_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p3_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            else if (slotIdx == 3)
                            {
                                Utility.MW.p4_Img.Source = faces[selectedDummyPlayerIdx[slotIdx]][0];
                                Utility.MW.p4_Name.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().playerName;
                                Utility.MW.p4_Hp.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                //Utility.MW.p4_Hp.Value = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxHp / 100 * 90;
                                Utility.MW.p4_Bomb.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().maxBomb;
                                Utility.MW.p4_Atk.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().atk;
                                Utility.MW.p4_Power.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().power;
                                Utility.MW.p4_Speed.Content = playerLoaders[selectedDummyPlayerIdx[slotIdx]].getDummyPlayer().speed;
                            }
                            break;
                        case Key.Space:
                            lockSelectedDummyPlayerIdx[slotIdx] = -1;
                            break;

                    }
                }
                else
                {
                    switch (e.Key)
                    {
                        case Key.Space:
                            lockSelectedDummyPlayerIdx[slotIdx] = 1;
                            break;
                    }
                }
            }
            else
            {
                if (devices.Count < MAX_PLAYERS)
                {
                    devices.Add(e.DeviceHnd);
                    selectedDummyPlayerIdx.Add(0);
                }

            }
        }