Esempio n. 1
0
/*
 * PollMouse - poll the mouse for it's state
 */
void PollMouse( int *status, int *row, int *col )
{
    struct      _MOUEVENTINFO   meinfo;
    struct      _MOUQUEINFO     mqinfo;
    USHORT                      readtype = 0;

    if( !MouGetNumQueEl( &mqinfo, mouseHandle ) ) {
        if( mqinfo.cEvents != 0 ) {
            if( !MouReadEventQue( &meinfo, &readtype, mouseHandle ) ) {
                lastStatus = 0;
                if( meinfo.fs & 0x0006 ) {
                    lastStatus |= MOUSE_LEFT_BUTTON_DOWN;
                }
                if( mouseHasTwoButtons ) {
                    if( meinfo.fs & 0x0078 ) {
                        lastStatus |= MOUSE_RIGHT_BUTTON_DOWN;
                    }
                } else {
                    if( meinfo.fs & 0x0018 ) {
                        lastStatus |= MOUSE_RIGHT_BUTTON_DOWN;
                    }
                    if( meinfo.fs & 0x0060 ) {
                        lastStatus |= MOUSE_MIDDLE_BUTTON_DOWN;
                    }
                }
                lastRow  = meinfo.row;
                lastCol  = meinfo.col;
            }
        }
    }

    *status = lastStatus;
    *col = lastCol;
    *row = lastRow;

} /* PollMouse */
Esempio n. 2
0
int ReadMouseEvent(TEvent *Event, ULONG EventMask) {
  static unsigned short PrevState   = 0;
  static unsigned short PrevButtons = 0;
  static TEvent  LastMouseEvent     = { evNone };
  static ULONG   LastEventTime      = 0;
  static ULONG   LastClick          = 0;
  static ULONG   LastClickTime      = 0;
  static ULONG   LastClickCount     = 0;
  MOUEVENTINFO   mi;
  unsigned short Buttons, State, Btn;
  USHORT fWait = MOU_NOWAIT;
  MOUQUEINFO mq;
  ULONG CurTime;

  DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &CurTime, 4);

  Event->What = evNone;
  MouGetNumQueEl(&mq, MouseHandle);

  if (mq.cEvents == 0) {
    if ((LastMouseEvent.What == evMouseAuto) && (EventMask & evMouseAuto)) {
      if (TM_DIFF(CurTime, LastEventTime) >= MouseAutoRepeat) {
        *Event = LastMouseEvent;
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastEventTime, 4);
        return 1;
      }
    }

    if (((LastMouseEvent.What == evMouseDown) ||
         (LastMouseEvent.What == evMouseMove))
        &&
        (LastMouseEvent.Mouse.Buttons)
        && (EventMask & evMouseAuto)) {
      if (TM_DIFF(CurTime, LastEventTime) >= MouseAutoDelay) {
        LastMouseEvent.What = evMouseAuto;
        *Event              = LastMouseEvent;
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastEventTime, 4);
        return 1;
      }
    }
    return 0;
  }

  if (MouReadEventQue(&mi, &fWait, MouseHandle) != 0) return 0;

  Event->Mouse.X = mi.col;
  Event->Mouse.Y = mi.row;
  State          = mi.fs;
  Btn            = Buttons = ((State & (2 | 4)) ? 1 : 0) |
                             ((State & (8 | 16)) ? 2 : 0) |
                             ((State & (32 | 64)) ? 4 : 0);

  if (Buttons != PrevButtons) {
    Buttons ^= PrevButtons;

    if (PrevButtons & Buttons) Event->What = evMouseUp;
    else Event->What = evMouseDown;
  } else {
    Event->What = evMouseMove;

    if ((Event->Mouse.X == LastMouseEvent.Mouse.X) &&
        (Event->Mouse.Y == LastMouseEvent.Mouse.Y)) return 0;
  }
  Event->Mouse.Buttons = Buttons;
  Event->Mouse.Count   = 1;
  PrevState            = State;
  PrevButtons          = Btn;

  if (Event->What == evMouseDown) {
    if (LastClickCount) {
      if (LastClick == Event->Mouse.Buttons) {
        if (TM_DIFF(CurTime, LastClickTime) <= MouseMultiClick) {
          Event->Mouse.Count = ++LastClickCount;
        } else {
          LastClickCount = 0;
        }
      } else {
        LastClick      = 0;
        LastClickCount = 0;
        LastClickTime  = 0;
      }
    }

    LastClick = Event->Mouse.Buttons;

    if (LastClickCount == 0) LastClickCount = 1;
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastClickTime, 4);
  }

  /*    if (Event->What == evMouseMove) {
          LastClick = 0;
          LastClickCount = 0;
          LastClickTime = 0;
      }*/
  {
    KBDINFO  ki;
    USHORT   Flags;
    TKeyCode KeyFlags = 0;

    ki.cb = sizeof(ki);
    KbdGetStatus(&ki, 0);
    Flags = ki.fsState;

    if ((Flags & (LEFTSHIFT | RIGHTSHIFT)) != 0) KeyFlags |= kfShift;

    if ((Flags & (LEFTCONTROL | RIGHTCONTROL)) != 0) KeyFlags |= kfCtrl;

    if ((Flags & (LEFTALT | RIGHTALT)) != 0) KeyFlags |= kfAlt;

    Event->Mouse.KeyMask = KeyFlags;
  }

  LastMouseEvent = *Event;
  DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastEventTime, 4);
  return 1;
}