Ejemplo n.º 1
0
/**
 * Run the command, we take into account the current selection and command parameters given.
 * @param CWnd* pWnd the last forground window.
 * @param const MYODD_STRING& szCommandLine the command line argument.
 * @param bool isPrivileged if we need administrator privilege to run this.
 * @return BOOL true.
 */
ActiveAction* Action::CreateActiveAction(CWnd* pWnd, const MYODD_STRING& szCommandLine, bool isPrivileged) const
{
  //  not sure how to do that...
  if ( Len() == 0)
  {
    return nullptr;
  }

  // we are about to execute a command, we don't know how long the command will last
  // a badly written plugin could take forever to return.
  BOOL bThen = hook_RejectKeyboad( FALSE );

  //  if we are here then we are going to load a user command
  //
  //  If the user did not pass any arguments/command line then we must get them from the clipboard.
  ActiveAction* aa;
  if( szCommandLine.length() == 0 )
  {
    aa = CreateActiveActionWithNoCommandLine( pWnd, isPrivileged);
  }
  else
  {
    //  so now, at last we can call the command line
    aa = CreateActiveActionDirect( pWnd, szCommandLine.c_str(), isPrivileged);
  }

  // now that we are back from calling the plugin, restore the keyboard state.
  hook_RejectKeyboad( bThen );

  return aa;
}
Ejemplo n.º 2
0
LRESULT HookWnd::OnHookKeyUp(WPARAM wParam, LPARAM lParam)
{
  TRACE("KeyUp 0x%x\n", wParam);

  //  check the key that the user had released
  //  if it the special key then tell the user that the key is no longer down
  if (IsSpecialKey(wParam))
  {
    //  the key is no longer down
    //  but was it down at all to start with? - (sanity check)
    if ((_keyState & ACTION_MAINKEY_DOWN) == ACTION_MAINKEY_DOWN)
    {
      //  remove the fact that the key was pressed.
      //  do that next time we come around here we don't do it again
      _keyState &= ~ACTION_MAINKEY_DOWN;

      // execute the command
      _application.ExecuteCurrentAction();

      // we are hidding the current action
      _actions.CurrentActionReset();

      //  hide the window
      _display.Hide();

      //  tell the system that we can now accept key press
      hook_RejectKeyboad(FALSE);
      _display.Inactive();
    }
  }

  switch (wParam)
  {
  case VK_SHIFT:
  case VK_RSHIFT:
  case VK_LSHIFT:
    _keyState &= ~ACTION_SHIFT_DOWN;
    _keyState &= ~ACTION_LSHIFT_DOWN;
    break;

  default:
    break;
  }

  /**
   * The WM_KEYUP message is posted to the window with the keyboard focus when a nonsystem key is released.
   * A nonsystem key is a key that is pressed when the ALT key is not pressed,
   * or a keyboard key that is pressed when a window has the keyboard focus.
   */
  return 0L;
}
Ejemplo n.º 3
0
LRESULT HookWnd::OnHookKeyDown(WPARAM wParam, LPARAM lParam)
{
  TRACE("KeyDown 0x%x\n", wParam);

  /**
   * The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed.
   * A nonsystem key is a key that is pressed when the ALT key is not pressed.
   */

   //  if it is the special key then tell the system that from now own
   //  we need to record keys and prevent any other key from passing accross.
  if (IsSpecialKey(wParam))
  {
    //  only do it if the key was NOT down previously.
    //  otherwise we will forever be reseting
    if ((_keyState & ACTION_MAINKEY_DOWN) != ACTION_MAINKEY_DOWN)
    {
      // we need to save the last forground window
      // because showing our dialog box will change things a bit.
      _application.SetLastForegroundWindow( );

      //  tell the system to no longer accept any more key
      _keyState |= ACTION_MAINKEY_DOWN;
      hook_RejectKeyboad(TRUE);
      _display.Active();

      //  reset the last command
      _actions.CurrentActionReset();
      _display.Show( _actions.ToChar() );
    }
  }

  //  if the special key is not down then we don't need to go any further
  if ((_keyState & ACTION_MAINKEY_DOWN) != ACTION_MAINKEY_DOWN)
  {
    return 0L;
  }

  switch (wParam)
  {
  case VK_BACK:     // backspace 
    _actions.CurrentActionBack();
    _display.Show( _actions.ToChar() );
    break;

  case 0x0A:        // linefeed 
  case VK_TAB:      // tab 
  case VK_RETURN:   // carriage return 
  case VK_CLEAR:
    break;

  case VK_ESCAPE:
    _actions.CurrentActionReset();
    _display.Show( _actions.ToChar() );
    break;

  case VK_DOWN:
    _actions.down();
    _display.Show( _actions.ToChar() );
    break;

  case VK_CAPITAL:
    break;

  case VK_UP:
    _actions.up();
    _display.Show( _actions.ToChar() );
    break;

  case VK_SHIFT:
  case VK_RSHIFT:
    _keyState |= ACTION_SHIFT_DOWN;
    break;

  case VK_LSHIFT:
    _keyState |= (ACTION_SHIFT_DOWN | ACTION_LSHIFT_DOWN);
    break;

  default:
  {
    BYTE ks[256];
    memset(ks, 0, sizeof(ks));
    GetKeyboardState(ks);
    WORD w;
    UINT scan = 0;

    ks[VK_SHIFT] = 1;
    if ((_keyState & ACTION_SHIFT_DOWN) == ACTION_SHIFT_DOWN)
    {
      //  force the shift key down.
      //  the low level keyboad does not alway pass the key(shift) before the letter key
      //  so we might not know that the shift key is pressed.
      //  so we set it here.
      ks[VK_SHIFT] = 129;
    }

    if (0 != ToAscii(wParam, scan, ks, &w, 0))
    {
      const auto c = static_cast<TCHAR>(CHAR(w));
      //  add the current character to the list of items
      _actions.CurrentActionAdd(c);

      //  make sure that the window is visible
      //  This will also force a refresh of the window
      _display.Show( _actions.ToChar() );
    }
  }
  break;
  }
  return 0L;
}