// add a new button to the config. you can alter it afterwards.
        public MJButtonTranslation addButton(EMJBUTTON btn, EMJFUNCTION func, byte FNidx = 0, string keys = "")
        {
            MJButtonTranslation bt = new MJButtonTranslation(btn, func, FNidx, keys);

            this.buttons.Add(bt);
            return(bt);
        }
 // 0.5.21 New constructor.
 public MJButtonTranslation(EMJBUTTON btn, EMJFUNCTION func, byte FN = 0, string keychars = "")
 {
     this.keyStroke = keychars;
     this.button    = btn;
     this.FNindex   = FN;
     this.assignFunction(func);
 }
Example #3
0
        // another action selected, show or hide some stuff.
        private void combo_Action_SelectedIndexChanged(object sender, EventArgs e)
        {
            // show key stuff if the keyboard action is selected.
            // keyboard is the second entry, zero based.
            EMJFUNCTION itm = EMJFUNCTION.SHOW_MENU;

            if (combo_Action.SelectedIndex >= 0)
            {
                itm = (EMJFUNCTION)combo_Action.Items[combo_Action.SelectedIndex];
            }

            // show repeating flag and keyboard keys.
            if (itm == EMJFUNCTION.KEYBOARD_COMBINATION || itm == EMJFUNCTION.VOLUME_UP || itm == EMJFUNCTION.VOLUME_DOWN)
            {
                panel_keystuff.Enabled = true;
                txt_repeattime.Text    = "" + Program.Input.Config.DefaultKeyStrokeDelay;
                if (itm == EMJFUNCTION.KEYBOARD_COMBINATION)
                {
                    txt_keystroke.Enabled = true;
                    lbl_keys.Enabled      = true;
                }
                else
                {
                    txt_keystroke.Enabled = false;
                    lbl_keys.Enabled      = false;
                }
            }
            else
            {
                // do not repeat at all costs :)
                chk_repeat.Checked     = false;
                txt_repeattime.Text    = "0";
                panel_keystuff.Enabled = false;
            }

            // maybe disable the FN checkbox when the FN button would need FN for itself.
            // FN is the last entry.
            if (itm == EMJFUNCTION.FN_MODIFICATOR)
            {
                chk_FN.Checked = false;
                chk_FN.Enabled = false;
            }
            else
            {
                chk_FN.Enabled = true;
            }
        }
        // 0.6.0: Another new constructor for loading a button.
        public MJButtonTranslation(TextReader br)
        {
            // read all the values from the file.
            string t = br.ReadLine();

            this.button = (EMJBUTTON)int.Parse(t);

            this.keyStroke = br.ReadLine();

            t            = br.ReadLine();
            this.FNindex = byte.Parse(t);

            t = br.ReadLine();
            EMJFUNCTION func = (EMJFUNCTION)int.Parse(t);

            t             = br.ReadLine();
            this.hitDelay = uint.Parse(t);

            this.assignFunction(func);
        }
Example #5
0
        // 0.6.9: create a button from the given values and return it.
        // was previously in the add-button function
        private MJButtonTranslation createButtonFromValues()
        {
            // empty button.
            MJButtonTranslation nobtn = new MJButtonTranslation(EMJBUTTON.None, EMJFUNCTION.SHOW_MENU);

            // Get the button.
            EMJBUTTON button = (EMJBUTTON)combo_Button.SelectedItem;
            // Get the action.
            EMJFUNCTION selaction = (EMJFUNCTION)combo_Action.SelectedItem;
            // keystroke, hitdelay and FN index.
            string mykeys   = txt_keystroke.Text;
            byte   fnidx    = 0;
            int    hitdelay = 0;

            // get the new hit delay.
            if (chk_repeat.Checked == true)
            {
                hitdelay = Int32.Parse(txt_repeattime.Text);
            }

            // get fn index.
            if (chk_FN.Checked == true)
            {
                fnidx = 1;
            }

            // get the desired button.
            // check if the button works.
            if (selaction == EMJFUNCTION.KEYBOARD_COMBINATION)
            {
                // it's a keyboard combination, it needs some keys.
                if (mykeys == "")
                {
                    MessageBox.Show("You need to set a key combination.", "Cannot create button:");
                    return(nobtn);
                }

                // check if the keyboard combination works.
                try
                {
                    // create the button for testing.
                    MJButtonTranslation testbtn = new MJButtonTranslation(button, EMJFUNCTION.KEYBOARD_COMBINATION, fnidx, mykeys);
                    // select the test box so nothing bad can happen.
                    txt_Test.Focus();
                    testbtn.hitKey();
                    btn_AddNew.Focus();
                }
                catch
                {
                    MessageBox.Show("The key combination is invalid! (break)", "Cannot create button.");
                    return(nobtn);
                }
            }

            // create the button
            MJButtonTranslation btn = new MJButtonTranslation(button, selaction, fnidx, mykeys);

            btn.hitDelay = (uint)hitdelay;

            // "external" settings.
            // set functions and stuff.
            switch (selaction)
            {
            case EMJFUNCTION.FN_MODIFICATOR:
            case EMJFUNCTION.SHOW_MENU:
            case EMJFUNCTION.SLOWER_MOVEMENT:
            case EMJFUNCTION.FASTER_MOVEMENT:
                Program.Input.Config.assignExternalFunction(btn);
                break;

            default:
                break;
            }

            // return the new button.
            return(btn);
        }
        // assign some of the functions (internal ones)
        public void assignFunction(EMJFUNCTION func)
        {
            this.function = func;

            // define default delegates.
            onButtonDown = new voidDelegate(voidFunc);
            onButtonUp   = new voidDelegate(voidFunc);
            actionText   = "!NOTHING!";

            switch (this.function)
            {
            case EMJFUNCTION.KEYBOARD_COMBINATION:
                onButtonDown = new voidDelegate(hitKey);
                actionText   = "Keyboard: " + keyStroke;
                break;

            case EMJFUNCTION.LEFT_MOUSE_BUTTON:
                onButtonDown = new voidDelegate(leftMouseDown);
                onButtonUp   = new voidDelegate(leftMouseUp);
                actionText   = "Left Mouse Button";
                break;

            case EMJFUNCTION.RIGHT_MOUSE_BUTTON:
                onButtonDown = new voidDelegate(rightMouseDown);
                onButtonUp   = new voidDelegate(rightMouseUp);
                actionText   = "Right Mouse Button";
                break;

            case EMJFUNCTION.MIDDLE_MOUSE_BUTTON:
                onButtonDown = new voidDelegate(middleMouseDown);
                onButtonUp   = new voidDelegate(middleMouseUp);
                actionText   = "Middle Mouse Button";
                break;

            case EMJFUNCTION.VOLUME_UP:
                onButtonDown = new voidDelegate(volumeUp);
                actionText   = "Volume UP";
                break;

            case EMJFUNCTION.VOLUME_DOWN:
                onButtonDown = new voidDelegate(volumeDown);
                actionText   = "Volume DOWN";
                break;

            case EMJFUNCTION.MUTE_VOLUME:
                onButtonDown = new voidDelegate(volumeMute);
                actionText   = "MUTE Volume";
                break;

            // The stick functions do not need to be assigned.
            // They are executed otherwise.
            case EMJFUNCTION.ARROW_KEYS:
                actionText = "Arrow Keys";
                break;

            case EMJFUNCTION.WASD_KEYS:
                actionText = "W A S D Keys";
                break;

            case EMJFUNCTION.MOUSE_MOVEMENT:
                actionText = "Mouse Movement";
                break;

            case EMJFUNCTION.MOUSE_WHEEL:
                actionText = "Mouse Wheel";
                break;

            default:
                break;
            }
        }