void main()
{
int rc;
HMOU msHandle;
MOUEVENTINFO msEventInfo;
USHORT ReadType = 0;

rc = MouOpen( NULL, &msHandle );
if( rc )
{
		printf("MouOpen error, rc = %d\n", rc);
		return;
}

rc = MouDrawPtr( msHandle );
while(1)
{
	rc = MouReadEventQue( &msEventInfo, &ReadType, msHandle );
	if( rc )
	{
		printf("MouReadEventQue error, rc = %d\n", rc);
		return;
	}
	if( msEventInfo.time )
	printf( "mousestate = %d\n",
		msEventInfo.fs
		);
	
	DosSleep( 100 );
}

}
Esempio n. 2
0
static void os2_getmouse(aa_context * c, int *x, int *y, int *b) {
  MOUEVENTINFO mouEvent;
  PTRLOC ptrLoc;
  USHORT mouwait = MOU_NOWAIT;

  MouGetPtrPos(&ptrLoc, hMou);
  MouReadEventQue(&mouEvent, &mouwait, hMou);
  *x = ptrLoc.col; *y = ptrLoc.row;
  if((mouEvent.fs==0)&&(mouEvent.col==0)&&(mouEvent.row==0)) { /* no event */
    *b = but;
    return;
  }
  if(mouEvent.fs&0x60)
    but |= AA_BUTTON2;
  else
    but &= ~AA_BUTTON2;
  if((mouEvent.fs&0x18)||(mouEvent.fs&0x60 && mouEvent.fs&0x06))
    but |= AA_BUTTON3;
  else
    but &= ~AA_BUTTON3;
  if(mouEvent.fs&0x06)
    but |= AA_BUTTON1;
  else
    but &= ~AA_BUTTON1;
  if(mouEvent.fs&0x01)
    but = 0;

  *b = but;
}
Esempio n. 3
0
static void
mousehandler()
{
    for (;;) {
	MOUEVENTINFO	m;
	unsigned short	status;
	clock_t		start;

#if 0
	if (MouGetDevStatus((PUSHORT) &status, mousenum) != 0
	    ||
	    (status & (MOUSE_UNSUPPORTED_MODE | MOUSE_DISABLED))
	) {
	    hidemouse();
	    (void) MouClose(mousenum);
	    DosExit(EXIT_THREAD, 0);
	}
#endif
	status = MOU_WAIT;
	MouReadEventQue((PMOUEVENTINFO) &m, (PUSHORT) &status, mousenum);
	/*
	 * If we don't get the control semaphore immediately,
	 * we do nothing. Delayed responses to mouse button
	 * presses could be confusing.
	 */
#if 0
	start = clock();
#endif
	if (DosSemRequest(control, SEM_IMMEDIATE_RETURN) != 0)
	    continue;
#if 0
	if (clock() != start) {
	    (void) fprintf(stderr, "mouse thread: %d\n", __LINE__);
	    DosSemClear(control);
	    continue;
	}
#endif
	/*
	 * Start of critical section.
	 */
	if (++keystrokes >= PSVKEYS)
	    lastevent = clock();
	if (State == NORMAL &&
		(m.fs & (MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN))) {
	    hidemouse();
	    mouseclick(m.row, m.col);
	    showmouse();
	}
	/*
	 * End of critical section.
	 */
	DosSemClear(control);
    }
}
//static void APIENTRY thMouse(ULONG data)
static void CC thMouse(void* data)
{
    MOUEVENTINFO Event;
    //USHORT MouHandle = 0;
    USHORT ReadType = 1;
    APIRET rc;

    ppMou = new PMObj;

    EditBoxCollection* pEdit = (EditBoxCollection*) data;

    rc = MouOpen( 0L, &pEdit->MouHandle);

    if(rc)
        return;

    rc = MouDrawPtr(pEdit->MouHandle);

    while(!pEdit->isDown())
    {
        rc = MouReadEventQue(&Event, &ReadType, pEdit->MouHandle);

        if(Event.fs & iMouseMask)
        {
            pEdit->lock();

            if(pEdit->current())
            {
                pEdit->track_beg();

                if(iSenseShift)
                {
                    if(kiLastKey.skey & shShift)
                        pEdit->current()->mark();
                    else
                        pEdit->current()->unmark();
                }

                if(iUpperStatus)
                    pEdit->SetMouse(Event.row - 1, Event.col);
                else
                    pEdit->SetMouse(Event.row, Event.col);

                pEdit->track_end();

                pEdit->draw();
            }
            pEdit->unlock();
        }
    }

    MouClose(pEdit->MouHandle);
}
Esempio n. 5
0
void main (void)
{
    MOUEVENTINFO  event;
    HMOU          MouHandle;
    USHORT        NButtons, wait = MOU_NOWAIT, eventmask;
    char          ev_name[1024];
    int           rc;

    rc = MouOpen (NULL, &MouHandle);
    printf ("rc = %d from MouOpen\n", rc);
    if (rc) return;

    MouGetNumButtons (&NButtons, MouHandle);
    printf ("%d buttons\n", NButtons);

    rc = MouGetEventMask (&eventmask, MouHandle);
    printf ("rc = %d from MouGetEventMask\n", rc);
    eventmask = (MOUSE_MOTION | MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN);
    eventmask |= (MOUSE_MOTION_WITH_BN1_DOWN |
                  MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_MOTION_WITH_BN3_DOWN);
    rc = MouSetEventMask (&eventmask, MouHandle);
    printf ("rc = %d from MouSetEventMask\n", rc);
    rc = MouDrawPtr (MouHandle);
    printf ("rc = %d from MouDrawPtr\n", rc);
    
    while (1)
    {
        rc = MouReadEventQue (&event, &wait, MouHandle);
        if (rc) printf ("rc = %d from MouReadEventQue\n", rc);
        if (rc) continue;
        if (event.time == 0) continue;
        
        ev_name[0] = '\0';
        if (event.fs & MOUSE_BN1_DOWN)             strcat (ev_name, "B1 down     | ");
        if (event.fs & MOUSE_BN2_DOWN)             strcat (ev_name, "B2 down     | ");
        if (event.fs & MOUSE_BN3_DOWN)             strcat (ev_name, "B3 down     | ");
        if (event.fs & MOUSE_MOTION)               strcat (ev_name, "Movement    | ");
        if (event.fs & MOUSE_MOTION_WITH_BN1_DOWN) strcat (ev_name, "B1 movement | ");
        if (event.fs & MOUSE_MOTION_WITH_BN2_DOWN) strcat (ev_name, "B2 movement | ");
        if (event.fs & MOUSE_MOTION_WITH_BN3_DOWN) strcat (ev_name, "B3 movement | ");
        if (ev_name[0] == '\0')                    strcat (ev_name, "release     | ");
        
        printf ("%s row = %3d, col = %3d, flags = %x\n", ev_name, event.row, event.col, event.fs);
    }

    MouClose (MouHandle);
}
Esempio n. 6
0
static int os2_getchar(aa_context * c, int wait) {
  KBDKEYINFO kbdkey;
  MOUEVENTINFO mouEvent;
  USHORT mouwait = MOU_NOWAIT;

  if(wait) {
    while(1) {
      KbdCharIn(&kbdkey, IO_NOWAIT, 0);
      if(kbdkey.fbStatus!=0)
	return check_keys(kbdkey);
      if(hMou!=-1) {
	MouReadEventQue(&mouEvent, &mouwait, hMou);
	/* mouse event! */
	if(!((mouEvent.fs==0)&&(mouEvent.col==0)&&(mouEvent.row==0))) {
          if(mouEvent.fs&0x60)
	    but |= AA_BUTTON2;
  	  else
    	    but &= ~AA_BUTTON2;
  	  if((mouEvent.fs&0x18)||(mouEvent.fs&0x60 && mouEvent.fs&0x06))
    	    but |= AA_BUTTON3;
  	  else
    	    but &= ~AA_BUTTON3;
  	  if(mouEvent.fs&0x06)
    	    but |= AA_BUTTON1;
  	  else
    	    but &= ~AA_BUTTON1;
  	  if(mouEvent.fs&0x01)
    	    but = 0;

	  return AA_NONE;
	}
      }
      DosSleep(0);
    }
  } else {
    KbdCharIn(&kbdkey, IO_NOWAIT, 0);
    if(kbdkey.fbStatus==0)
      return AA_NONE;
    else
      return check_keys(kbdkey);
  }
  return (AA_NONE);
}
Esempio n. 7
0
void TEventQueue::mouseThread(void* arg) {
  arg = arg;
  assert(! DosWaitEventSem(TThreads::hevMouse2, SEM_INDEFINITE_WAIT) );
  MouseEventType tempMouse;
  MOUEVENTINFO *info = &TThreads::tiled->mouseInfo;

  while (1) {
    do {
      jsSuspendThread
      USHORT type = 0; // non-blocking read
      MouReadEventQue(info, &type, TThreads::tiled->mouseHandle);
      if (info->time==0) {
        DosSleep(mousePollingDelay);
        if (mousePollingDelay < 500) mousePollingDelay += 5;
      } else {
        mousePollingDelay=0;
      }
    } while (info->time==0);
    tempMouse.buttons = ((info->fs & 06)  != 0) +
               (((info->fs & 030) != 0) << 1)+
               (((info->fs & 0140) != 0) << 2);
    tempMouse.where.x = info->col;
    tempMouse.where.y = info->row;
    tempMouse.doubleClick = False;

    jsSuspendThread
    DosRequestMutexSem(TThreads::hmtxMouse1,SEM_INDEFINITE_WAIT);
    if( (tempMouse.buttons!=curMouse.buttons) && eventCount < eventQSize ) {
      eventQTail->what = info->time/52; //*Ticks;
      eventQTail->mouse = tempMouse; // curMouse;
      if( ++eventQTail >= eventQueue + eventQSize ) eventQTail = eventQueue;
      eventCount++;
    }

    curMouse = tempMouse;

    APIRET rc = DosPostEventSem(TThreads::hevMouse1);
    assert( rc==0 || rc==ERROR_ALREADY_POSTED );
    assert(! DosReleaseMutexSem(TThreads::hmtxMouse1));
  }
  TThreads::deadEnd();
}
Esempio n. 8
0
void mouse_thread(void *p)
{
	HMOU h = mh;
	USHORT rd = MOU_WAIT;
	DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 31, 0);
	while (1) {
	if (MouReadEventQue(ev, &rd, h)) return;
	if (!mouse_works) goto ret;
	_fmutex_request(&sem, _FMR_IGNINT);
	xpos += ev->col;
	ypos += ev->row;
	buttons =
	  ((ev->fs & (MOUSE_MOTION_WITH_BN1_DOWN|MOUSE_BN1_DOWN)) ? 1 : 0) +
	  ((ev->fs & (MOUSE_MOTION_WITH_BN2_DOWN|MOUSE_BN2_DOWN)) ? 2 : 0) +
	  ((ev->fs & (MOUSE_MOTION_WITH_BN3_DOWN|MOUSE_BN3_DOWN)) ? 4 : 0);
	_fmutex_release(&sem);
	}
	ret:
	MouClose(h);
}
Esempio n. 9
0
static void hb_gt_os2_mouse_ReadMouseState( void )
{
   if( s_uMouHandle )
   {
      USHORT WaitOption = 0;  /* 1 = wait until mouse event exist, 0 = don't */
      MOUEVENTINFO MouEvent;
      if( MouReadEventQue( &MouEvent, &WaitOption, s_uMouHandle ) == NO_ERROR )
      {
         ULONG ulDiff;
         int i;

         ulDiff = s_ulMouseLastState ^ MouEvent.fs;
         s_ulMouseLastState = MouEvent.fs;

         for( i = 0; i < 3; ++i )
         {
            if( ulDiff & s_ButtonMask[ i ] )
            {
               if( s_ulMouseLastState & s_ButtonMask[ i ] )
               {
                  s_ButtonState[ i ].fDown = HB_TRUE;
                  s_ButtonState[ i ].iPressed++;
                  s_ButtonState[ i ].iPressRow = MouEvent.row;
                  s_ButtonState[ i ].iPressCol = MouEvent.col;
                  s_ButtonState[ i ].ulPressTime = MouEvent.time;
               }
               else
               {
                  s_ButtonState[ i ].fDown = HB_FALSE;
                  s_ButtonState[ i ].iReleased++;
                  s_ButtonState[ i ].iReleaseRow = MouEvent.row;
                  s_ButtonState[ i ].iReleaseCol = MouEvent.col;
                  s_ButtonState[ i ].ulReleaseTime = MouEvent.time;
               }
            }
         }
      }
   }
}
Esempio n. 10
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. 11
0
static void
mouse_server(unsigned long ignored GCC_UNUSED)
{
    unsigned short fWait = MOU_WAIT;
    /* NOPTRRECT mourt = { 0,0,24,79 }; */
    MOUEVENTINFO mouev;
    HMOU hmou;
    unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN;
    int nbuttons = 3;
    int oldstate = 0;
    char err[80];
    unsigned long rc;

    /* open the handle for the mouse */
    if (MouOpen(NULL, &hmou) == 0) {
	rc = MouSetEventMask(&mask, hmou);
	if (rc) {		/* retry with 2 buttons */
	    mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN;
	    rc = MouSetEventMask(&mask, hmou);
	    nbuttons = 2;
	}
	if (rc == 0 && MouDrawPtr(hmou) == 0) {
	    for (;;) {
		/* sit and wait on the event queue */
		rc = MouReadEventQue(&mouev, &fWait, hmou);
		if (rc) {
		    snprintf(err, sizeof(err),
			     "Error reading mouse queue, rc=%lu.\r\n", rc);
		    break;
		}
		if (!mouse_activated)
		    goto finish;

		/*
		 * OS/2 numbers a 3-button mouse inconsistently from other
		 * platforms:
		 *      1 = left
		 *      2 = right
		 *      3 = middle.
		 */
		if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN)
		    write_event(mouev.fs & MOUSE_BN1_DOWN,
				mouse_buttons[1], mouev.col, mouev.row);
		if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN)
		    write_event(mouev.fs & MOUSE_BN2_DOWN,
				mouse_buttons[3], mouev.col, mouev.row);
		if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN)
		    write_event(mouev.fs & MOUSE_BN3_DOWN,
				mouse_buttons[2], mouev.col, mouev.row);

	      finish:
		oldstate = mouev.fs;
	    }
	} else
	    snprintf(err, sizeof(err),
		     "Error setting event mask, buttons=%d, rc=%lu.\r\n",
		     nbuttons, rc);

	DosWrite(2, err, strlen(err), &rc);
	MouClose(hmou);
    }
    DosExit(EXIT_THREAD, 0L);
}
Esempio n. 12
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;
}