Adding hotkey to MES

I am struggling to get a hotkey to launch a form in MES. So far I managed to cobble together some code from a variety of threads on this site as well as some C# threads.

I would like to launch the Start Activity form. That button is already on MES, but I don’t know how to call that button/process directly so I added the Start Activity DLL file to Menu Maintenance with ID SSSM9999, and I am trying to call it with this code:

private void Form_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.J)
     {
          ProcessCaller.LaunchForm(this.oTrans, "SSSM9999");
          e.SuppressKeyPress = true;
     }
}

I’m not sure if I need to define anything else, and I don’t know how to enable KeyPreview for the form (which seems to be an important step).

1 Like

I learned a little more about KeyDown, KeyUp, and KeyPress, and have since changed KeyDown to KeyPress since it makes more sense for what I want (form fires when “J” key is pressed).

1 Like

This is how my code is set up currently.

 public class Script
 {
      public void InitializeCustomCode()
      {
           Erp.Menu.Mes.MESMenu mainPanel1 = MESMenu;
           mainPanel1.KeyPress += new KeyPressEventHandler(mainPanel1_KeyPress)
      }

      private void MESMenu_Load(object sender, EventArgs args)
      {
           mainPanel1.KeyPreview = true;
      }

      private void mainPanel1_KeyPress(object sender, KeyPressEventArgs e)
      {
           if (e.KeyChar == (char)106)
           {
                MessageBox.Show("Success!");
                ProcessCaller.LaunchForm(this.oTrans, "SSSM9999");
           }
 }

I am getting this error when I compile: “Error: CS1061 - line 119 (1624) - ‘Ice.Lib.Framework.EpiPanel’ does not contain a definition for ‘KeyPreview’ and no extension method ‘KeyPreview’ accepting a first argument of type ‘Ice.Lib.Framework.EpiPanel’ could be found (are you missing a using directive or an assembly reference?)”

KeyPreview is at the Form Level not the Panel.
It should just be
MESMenu.KeyPreview =true;

Thanks! I had to make some additional tweaks to the code, but now it works!

 public class Script
 {
      public void InitializeCustomCode()
      {
           MESMenu.KeyPress += new KeyPressEventHandler(MESMenu_KeyPress)
      }

      private void MESMenu_Load(object sender, EventArgs args)
      {
           MESMenu.KeyPreview = true;
      }

      private void MESMenu_KeyPress(object sender, KeyPressEventArgs e)
      {
           if (e.KeyChar == (char)106)
           {
                ProcessCaller.LaunchForm(this.oTrans, "SSSM9999");
           }
 }
3 Likes

@fredmeissner would you be available to discuss this MES customization script & Start Production Activity barcode script offline? Please let me know. Very interested in accomplishing same but need a little guidance.

Sure! This was a while ago but I can try and help.