Problems With "HotKeys" in OnChartEvent

 

Hello,

I am trying to trap the left and right Square Brackets "[" "]" and the left and right Curly Braces "{" "}". On my keyboard, the curly braces are generated by the Shift+[ and Shift+]. So, two keys on the keyboard should provide the 4 values I need. When I press the keys in an editor, as you can see, the correct characters are printed. However, the values for "[" in lparam variable is 219 (it should be 91) and for "]", it comes through as 221 (it should be 93). So, I don't understand why the event handler gets the wrong values for the square brackets.

For the curly braces, I have to press the Shift key and all that comes through to the event handler is 16. I'm not sure how to handle a shifted keystroke to get effectively, a single character of "{" or "}". I've played around with this for a while and cannot see an obvious solution to these issues. The code segments are as below:

#define TOGGLE_SHOW 83
#define TOGGLE_FORWARD 93
#define TOGGLE_BACKWARD 91
#define TOGGLE_ADD 125
#define TOGGLE_SUBTRACT 123

// 219 [
// 221 ]


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,// Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam  // Parameter of type string events
                 )
  {
//---
   if(id==CHARTEVENT_KEYDOWN)
     {
      //---
      if(lparam==TOGGLE_SHOW)
        {
         if(SquaresHidden)
           {
            //--- show
            ShowRangeObject(true);
           }
         else
           {
            //--- hide
            HideRangeObject();
           }
         //---
         SquaresHidden=!SquaresHidden;
        }
      else
        {
         RangeLine.OnHotKeyDown(lparam);
        }
     }
  }


//--- Following code in CRangeLine class

void CRangeLine::OnHotKeyDown(long value)
  {
//--- avoid processing if cycles isn't live
   if(CheckPointer(_cycles)!=POINTER_DYNAMIC)
      return;
//---
   switch((int)value)
     {
      case TOGGLE_FORWARD:
        {
         //---
         break;
        }
      case TOGGLE_BACKWARD:
        {
         //---
         //---
         break;
        }
      case TOGGLE_ADD:
         Print("Add");
         break;
      case TOGGLE_SUBTRACT:
         Print("Subtract");
         break;
     }
//---
  }


If anyone can help point me in the right direction, I'd really appreciate it.

Thank you.

 
Geester:

Hello,

I am trying to trap the left and right Square Brackets "[" "]" and the left and right Curly Braces "{" "}". On my keyboard, the curly braces are generated by the Shift+[ and Shift+]. So, two keys on the keyboard should provide the 4 values I need. When I press the keys in an editor, as you can see, the correct characters are printed. However, the values for "[" in lparam variable is 219 (it should be 91) and for "]", it comes through as 221 (it should be 93). So, I don't understand why the event handler gets the wrong values for the square brackets.

For the curly braces, I have to press the Shift key and all that comes through to the event handler is 16. I'm not sure how to handle a shifted keystroke to get effectively, a single character of "{" or "}". I've played around with this for a while and cannot see an obvious solution to these issues. The code segments are as below:

If anyone can help point me in the right direction, I'd really appreciate it.

Thank you.

Experiment with this:

   if(id==CHARTEVENT_KEYDOWN)
   {
      if (TranslateKey((int)lparam)=='[')
         Print ("[ key pressed");
      else
      if (TranslateKey((int)lparam)==']')
         Print ("] key pressed");
      else
      if (TranslateKey((int)lparam)=='{')
         Print ("{ key pressed");
      else
      if (TranslateKey((int)lparam)=='}')
         Print ("} key pressed");
   }
 
Seng Joo Thio:

Experiment with this:

Thank you very much for your suggestion! I really appreciate it :)

 
Seng Joo Thio:

Experiment with this:

Just a heads up, your solution works like a charm! Thank you :D

Reason: