예제 #1
0
 private void media_play_pause_Click(object sender, RoutedEventArgs e)
 {
     // this needs to be changed to accomidate actually checking if the
     // music is playing to be correct all the time
     if (media_play_pause.Content.Equals("Play"))
     {
         media_play_pause.Content = new PackIcon {
             Kind = PackIconKind.PlayPause
         };
     }
     else
     {
         media_play_pause.Content = new PackIcon {
             Kind = PackIconKind.PlayPause
         };
     }
     Shortcut.send(new VirtualKeyShort.Key[] { VirtualKeyShort.Key.MEDIA_PLAY_PAUSE });
 }
예제 #2
0
        // Initializes the window to not steal focus by default
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            shortcut = new List <VirtualKeyShort.Key>();

            // sets the window so that a click does not bring it into focus
            helper = new WindowInteropHelper(this);
            SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVE);

            // this lets WndProc be overriden so that we can get the click massage
            HwndSource source = PresentationSource.FromVisual(this) as HwndSource;

            source.AddHook(WndProc);

            // this activates the window so that when we start it
            // it does not jump to the back of all windows
            this.Activate();

            // Starts the bottom bar
            string docPath    = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string openBtmBar = "";

            using (StreamReader sr = new StreamReader(System.IO.Path.Combine(docPath, "KeyStrokesApp\\bottmBar.txt"), true))
            {
                openBtmBar = sr.ReadLine();
            }
            if (openBtmBar == "yes")
            {
                bottomBar.Visibility = Visibility.Visible;
            }
            else
            {
                bottomBar.Visibility = Visibility.Hidden;
            }

            // Starts the previous layout
            //string docPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string gridXaml = " ";

            using (StreamReader sr = new StreamReader(System.IO.Path.Combine(docPath, "KeyStrokesApp\\saveLayout.txt"), true))
            {
                gridXaml = sr.ReadLine();
            }


            if (gridXaml != null)
            {
                StringReader  stringReader = new StringReader(gridXaml);
                XmlReader     xmlReader    = XmlReader.Create(stringReader);
                UniformGrid   uniformGrid  = (UniformGrid)XamlReader.Load(xmlReader);
                List <Button> buttonList   = new List <Button>();
                foreach (Button btn in uniformGrid.Children)
                {
                    Console.WriteLine(btn.Content);
                    buttonList.Add(btn);
                }
                uniformGrid.Children.Clear();

                // Goes through and adds the app items
                List <string> buttonApps  = new List <string>();
                List <string> buttonSC    = new List <string>();
                List <string> buttonNames = new List <string>();
                using (StreamReader sr = new StreamReader(System.IO.Path.Combine(docPath, "KeyStrokesApp\\saveClicks.txt"), true))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        buttonNames.Add(line.Split('|')[0]);
                        buttonApps.Add(line.Split('|')[1]);
                        buttonSC.Add(line.Split('|')[2]);
                    }
                }

                foreach (Button btn in buttonList)
                {
                    int i = buttonNames.IndexOf(btn.Content.ToString());
                    if (i != -1)
                    {
                        List <VirtualKeyShort.Key> shortcut = new List <VirtualKeyShort.Key>();

                        Action <object, RoutedEventArgs> click = null;
                        click = (se, ev) =>
                        {
                            // Add Application

                            if (buttonApps[i].Length > 1)
                            {
                                Process cmd = new Process();
                                cmd.StartInfo.FileName = "cmd.exe";
                                cmd.StartInfo.RedirectStandardInput  = true;
                                cmd.StartInfo.RedirectStandardOutput = true;
                                cmd.StartInfo.CreateNoWindow         = true; // true hides cmd prompt
                                cmd.StartInfo.UseShellExecute        = false;
                                cmd.Start();
                                cmd.StandardInput.WriteLine(buttonApps[i]);
                                cmd.StandardInput.Flush();
                                cmd.StandardInput.Close();
                                cmd.WaitForExit();
                            }
                        };

                        List <string> shortcutStr = new List <string>();

                        for (int j = 0; j < buttonSC[i].Split(' ').Length - 1; j++)
                        {
                            shortcutStr.Add(buttonSC[i].Split(' ')[j]);
                        }
                        foreach (string sh in shortcutStr)
                        {
                            if (sh.Length > 1)
                            {
                                VirtualKeyShort.Key x = (VirtualKeyShort.Key)System.Enum.Parse(typeof(VirtualKeyShort.Key), sh);
                                shortcut.Add((VirtualKeyShort.Key)x);
                            }
                        }

                        if (shortcut.Count != 0)
                        {
                            List <VirtualKeyShort.Key> holder = new List <VirtualKeyShort.Key>(shortcut);
                            click += (se, ev) =>
                            {
                                Shortcut.send(holder.ToArray());
                            };
                        }
                        grid.addButton(btn.Content.ToString(), click);
                    }
                }
            }
        }
예제 #3
0
 private void redo_Click(object sender, RoutedEventArgs e)
 {
     Shortcut.send(new VirtualKeyShort.Key[] { VirtualKeyShort.Key.CONTROL, VirtualKeyShort.Key.KEY_Y });
 }
예제 #4
0
 private void media_forward_Click(object sender, RoutedEventArgs e)
 {
     Shortcut.send(new VirtualKeyShort.Key[] { VirtualKeyShort.Key.MEDIA_NEXT_TRACK });
 }
예제 #5
0
 // Bottom bar, all the words should be changed to icons and made to look much much better
 private void media_back_Click(object sender, RoutedEventArgs e)
 {
     Shortcut.send(new VirtualKeyShort.Key[] { VirtualKeyShort.Key.MEDIA_PREV_TRACK });
 }
예제 #6
0
        private void Click_Confirm(object sender, RoutedEventArgs e)
        {
            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            // assigns the app name
            String ButtonText = "ShortCut";

            if (!String.IsNullOrEmpty(nameInput.Text))
            {
                ButtonText = this.nameInput.Text;    // name of the app
                //newButton.Name = this.nameInput.Text; add this to addbutton thing
            }

            // make it so that the buttons don't have the same name
            List <string> buttonNames = new List <string>();

            using (StreamReader sr = new StreamReader(System.IO.Path.Combine(docPath, "KeyStrokesApp\\saveClicks.txt"), true))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    buttonNames.Add(line.Split('|')[0]);
                }
            }
            string result = " ";

            while (result != null)
            {
                result = buttonNames.FirstOrDefault(x => x == ButtonText);
                if (result != null)
                {
                    ButtonText += "_1";
                }
            }

            string outStr = ButtonText;

            outStr += "|";
            // will hold the click handler
            Action <object, RoutedEventArgs> click = null;

            // assigns the app to launch
            string hold = appInput.Text;
            string str  = "";

            if (!(String.IsNullOrEmpty(hold)))
            {
                String[] spear   = { "," };
                String[] strlist = hold.Split(spear, StringSplitOptions.RemoveEmptyEntries);
                foreach (String st in strlist)
                {
                    if (str.Length > 1)
                    {
                        str += " & ";
                    }
                    string stTrim = st.Trim();
                    // harvest shortcuts from the start menu folder
                    String[] shortcut = null;
                    if (!stTrim.Contains(":\\"))
                    {
                        shortcut = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), stTrim + ".lnk", SearchOption.AllDirectories);
                    }

                    // start command: start "" "<program>"
                    str  = "";
                    str += "start \"\" \"";
                    // If we found a shortcut, we can add it to the start command
                    if (shortcut != null && shortcut.Length != 0)
                    {
                        str += shortcut[0];
                    }
                    else
                    {
                        str += stTrim;
                    }
                    str += "\"";
                }
                if (str.Length > 1)
                {
                    click = (se, ev) =>
                    {
                        Process cmd = new Process();
                        cmd.StartInfo.FileName = "cmd.exe";
                        cmd.StartInfo.RedirectStandardInput  = true;
                        cmd.StartInfo.RedirectStandardOutput = true;
                        cmd.StartInfo.CreateNoWindow         = true; // true hides cmd prompt
                        cmd.StartInfo.UseShellExecute        = false;
                        cmd.Start();
                        cmd.StandardInput.WriteLine(str);
                        cmd.StandardInput.Flush();
                        cmd.StandardInput.Close();
                        cmd.WaitForExit();
                    };
                }
            }

            // assigns the keyboard shortcuts to launch
            if (shortcut.Count != 0)
            {
                // by making a copy here it makes each button send its own shortcut
                // otherwise all keys send the same shortcut
                List <VirtualKeyShort.Key> holder = new List <VirtualKeyShort.Key>(shortcut);
                click += (se, ev) =>
                {
                    Shortcut.send(holder.ToArray());
                };
            }

            // don't let the user add an empty button...
            if (click != null)
            {
                main.grid.addButton(ButtonText, click);
                Click_Cancel(sender, e);
                main.menu_control.Visibility = Visibility.Collapsed;


                // save it
                using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(docPath, "KeyStrokesApp\\saveClicks.txt"), true))
                {
                    if (str.Length > 0)
                    {
                        outStr += str;
                    }
                    else
                    {
                        outStr += " ";
                    }
                    outStr += "|";

                    if (shortcut.Count != 0)
                    {
                        for (int i = 0; i < shortcut.Count; i++)
                        {
                            outStr += shortcut[i];
                            outStr += " ";
                        }
                    }
                    else
                    {
                        outStr += " ";
                    }

                    outputFile.WriteLine(outStr);
                }
            }

            keyEnum.SelectedIndex = 0;
        }