void * CaptureUserInput(void * arg) {
	int i;
	
	GetMyDeviceType();
	ReadDeviceKeyDB();
	
	printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event));
	maxEventPlusOne = -1;
			
	for (i=0; i<=MAX_INPUT_FILE_ID; i++) {		
		if (nKeyEntries[i] == 0) {
			inputEvents[i] = -1;
		} else {
			inputEvents[i] = OpenInputDevice(i);
			if (inputEvents[i] > maxEventPlusOne) maxEventPlusOne = inputEvents[i];
		}
	}
	maxEventPlusOne++;	
	
	while (1) {
		if (!HandleEvents()) break;
	}

	printf("Thread CaptureUserInput() exit.\n");

	for (i=0; i<=MAX_INPUT_FILE_ID; i++) {
		CloseInputDevice(i);
	}
	
	return 0;
}
Exemplo n.º 2
0
void * CaptureUserInput(void * arg) { 
	int i;
	
	__android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() ", "pre_getMyDeviceType");
	GetMyDeviceType();
	__android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() ", "pre_ReadDeviceKeyDB");
	ReadDeviceKeyDB();
	
	__android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() ", "post_ReadDeviceKeyDB");
	printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event));
	maxEventPlusOne = -1;
			
	char aLine[256];
	for (i=0; i<=MAX_INPUT_FILE_ID; i++) {		
		sprintf(aLine, "i = %d", i);
		if (nKeyEntries[i] == 0) {
			inputEvents[i] = -1;
		} else {
			inputEvents[i] = OpenInputDevice(i);
			if (inputEvents[i] > maxEventPlusOne) {
				maxEventPlusOne = inputEvents[i];
				sprintf(aLine, "NOT_EXPECTED: i = %d, inputEvents[i] (%d) > maxEventPlusOne = %d", 
					i, inputEvents[i], maxEventPlusOne);
				#ifdef TEST_INPUT
				WriteUserInputLog("libpcap: b CaptureUserInput() nKeyEntries[i] != 0 ", aLine);
				#endif
			} 
		}
	}
	maxEventPlusOne++;	
	
	while (1) {
		if  (!HandleEvents()) { 
		    #ifdef TEST_INPUT
		    WriteUserInputLog("libpcap: After HandleEvents returns 0 in CaptureUserInput() ", 
					"setting exitFlag = 3 and breaking from loop");
		    #endif
		    exitFlag = 3; 
		    break; 
		}
		if (exitFlag == 4) { 
		    #ifdef TEST_INPUT
		    WriteUserInputLog("libpcap: After HandleEvents exitFlag is 4 ", 
					"setting exitFlag = 3 and breaking from loop");
		    #endif
		    exitFlag = 3; 
		    break; 
		}
	}
	printf("Thread CaptureUserInput() exit.\n");
	__android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() exit", "EXIT");
	printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event));
	
	for (i=0; i<=MAX_INPUT_FILE_ID; i++) {
		CloseInputDevice(i);
	}
	CloseUserInputLog();
	return 0;
}
Exemplo n.º 3
0
int
ProcXOpenDevice(ClientPtr client)
{
    xInputClassInfo evbase[numInputClasses];
    int j = 0;
    int status = Success;
    xOpenDeviceReply rep;
    DeviceIntPtr dev;

    REQUEST(xOpenDeviceReq);
    REQUEST_SIZE_MATCH(xOpenDeviceReq);

    if (stuff->deviceid == inputInfo.pointer->id ||
	stuff->deviceid == inputInfo.keyboard->id) {
	SendErrorToClient(client, IReqCode, X_OpenDevice, 0, BadDevice);
	return Success;
    }

    if ((dev = LookupDeviceIntRec(stuff->deviceid)) == NULL) {	/* not open */
	for (dev = inputInfo.off_devices; dev; dev = dev->next)
	    if (dev->id == stuff->deviceid)
		break;
	if (dev == NULL) {
	    SendErrorToClient(client, IReqCode, X_OpenDevice, 0, BadDevice);
	    return Success;
	}
    }

    OpenInputDevice(dev, client, &status);
    if (status != Success) {
	SendErrorToClient(client, IReqCode, X_OpenDevice, 0, status);
	return Success;
    }

    rep.repType = X_Reply;
    rep.RepType = X_OpenDevice;
    rep.sequenceNumber = client->sequence;
    if (dev->key != NULL) {
	evbase[j].class = KeyClass;
	evbase[j++].event_type_base = event_base[KeyClass];
    }
Exemplo n.º 4
0
int
ProcXOpenDevice(ClientPtr client)
{
    xInputClassInfo evbase[numInputClasses];
    int j = 0;
    int status = Success;
    xOpenDeviceReply rep;
    DeviceIntPtr dev;

    REQUEST(xOpenDeviceReq);
    REQUEST_SIZE_MATCH(xOpenDeviceReq);

    status = dixLookupDevice(&dev, stuff->deviceid, client, DixUseAccess);

    if (status == BadDevice) {  /* not open */
        for (dev = inputInfo.off_devices; dev; dev = dev->next)
            if (dev->id == stuff->deviceid)
                break;
        if (dev == NULL)
            return BadDevice;
    } else if (status != Success)
        return status;

    if (IsMaster(dev))
        return BadDevice;

    OpenInputDevice(dev, client, &status);
    if (status != Success)
        return status;

    memset(&rep, 0, sizeof(xOpenDeviceReply));
    rep.repType = X_Reply;
    rep.RepType = X_OpenDevice;
    rep.sequenceNumber = client->sequence;
    if (dev->key != NULL) {
        evbase[j].class = KeyClass;
        evbase[j++].event_type_base = event_base[KeyClass];
    }
Exemplo n.º 5
0
/*
 * RawInputThreadMain
 *
 * Reads data from input devices and supports win32 timers
 */
VOID NTAPI
RawInputThreadMain()
{
    NTSTATUS MouStatus = STATUS_UNSUCCESSFUL, KbdStatus = STATUS_UNSUCCESSFUL, Status;
    IO_STATUS_BLOCK MouIosb, KbdIosb;
    PFILE_OBJECT pKbdDevice = NULL, pMouDevice = NULL;
    LARGE_INTEGER ByteOffset;
    //LARGE_INTEGER WaitTimeout;
    PVOID WaitObjects[3], pSignaledObject = NULL;
    ULONG cWaitObjects = 0, cMaxWaitObjects = 1;
    MOUSE_INPUT_DATA MouseInput;
    KEYBOARD_INPUT_DATA KeyInput;

    ByteOffset.QuadPart = (LONGLONG)0;
    //WaitTimeout.QuadPart = (LONGLONG)(-10000000);

    ptiRawInput = GetW32ThreadInfo();
    ptiRawInput->TIF_flags |= TIF_SYSTEMTHREAD;
    ptiRawInput->pClientInfo->dwTIFlags = ptiRawInput->TIF_flags;

    TRACE("Raw Input Thread %p\n", ptiRawInput);

    KeSetPriorityThread(&PsGetCurrentThread()->Tcb,
                        LOW_REALTIME_PRIORITY + 3);

    UserEnterExclusive();
    StartTheTimers();
    UserLeave();

    for (;;)
    {
        if (!ghMouseDevice)
        {
            /* Check if mouse device already exists */
            Status = OpenInputDevice(&ghMouseDevice, &pMouDevice, L"\\Device\\PointerClass0" );
            if (NT_SUCCESS(Status))
            {
                ++cMaxWaitObjects;
                TRACE("Mouse connected!\n");
            }
        }
        if (!ghKeyboardDevice)
        {
            /* Check if keyboard device already exists */
            Status = OpenInputDevice(&ghKeyboardDevice, &pKbdDevice, L"\\Device\\KeyboardClass0");
            if (NT_SUCCESS(Status))
            {
                ++cMaxWaitObjects;
                TRACE("Keyboard connected!\n");
                // Get and load keyboard attributes.
                UserInitKeyboard(ghKeyboardDevice);
                UserEnterExclusive();
                // Register the Window hotkey.
                UserRegisterHotKey(PWND_BOTTOM, IDHK_WINKEY, MOD_WIN, 0);
                // Register the debug hotkeys.
                StartDebugHotKeys();
                UserLeave();
            }
        }

        /* Reset WaitHandles array */
        cWaitObjects = 0;
        WaitObjects[cWaitObjects++] = MasterTimer;

        if (ghMouseDevice)
        {
            /* Try to read from mouse if previous reading is not pending */
            if (MouStatus != STATUS_PENDING)
            {
                MouStatus = ZwReadFile(ghMouseDevice,
                                       NULL,
                                       NULL,
                                       NULL,
                                       &MouIosb,
                                       &MouseInput,
                                       sizeof(MOUSE_INPUT_DATA),
                                       &ByteOffset,
                                       NULL);
            }

            if (MouStatus == STATUS_PENDING)
                WaitObjects[cWaitObjects++] = &pMouDevice->Event;
        }

        if (ghKeyboardDevice)
        {
            /* Try to read from keyboard if previous reading is not pending */
            if (KbdStatus != STATUS_PENDING)
            {
                KbdStatus = ZwReadFile(ghKeyboardDevice,
                                       NULL,
                                       NULL,
                                       NULL,
                                       &KbdIosb,
                                       &KeyInput,
                                       sizeof(KEYBOARD_INPUT_DATA),
                                       &ByteOffset,
                                       NULL);

            }
            if (KbdStatus == STATUS_PENDING)
                WaitObjects[cWaitObjects++] = &pKbdDevice->Event;
        }

        /* If all objects are pending, wait for them */
        if (cWaitObjects == cMaxWaitObjects)
        {
            Status = KeWaitForMultipleObjects(cWaitObjects,
                                              WaitObjects,
                                              WaitAny,
                                              UserRequest,
                                              KernelMode,
                                              TRUE,
                                              NULL,//&WaitTimeout,
                                              NULL);

            if ((Status >= STATUS_WAIT_0) &&
                (Status < (STATUS_WAIT_0 + (LONG)cWaitObjects)))
            {
                /* Some device has finished reading */
                pSignaledObject = WaitObjects[Status - STATUS_WAIT_0];

                /* Check if it is mouse or keyboard and update status */
                if (pSignaledObject == &pMouDevice->Event)
                    MouStatus = MouIosb.Status;
                else if (pSignaledObject == &pKbdDevice->Event)
                    KbdStatus = KbdIosb.Status;
                else if (pSignaledObject == MasterTimer)
                {
                    ProcessTimers();
                }
                else ASSERT(FALSE);
            }
        }

        /* Have we successed reading from mouse? */
        if (NT_SUCCESS(MouStatus) && MouStatus != STATUS_PENDING)
        {
            TRACE("MouseEvent\n");

            /* Set LastInputTick */
            IntLastInputTick(TRUE);

            /* Process data */
            UserEnterExclusive();
            UserProcessMouseInput(&MouseInput);
            UserLeave();
        }
        else if (MouStatus != STATUS_PENDING)
            ERR("Failed to read from mouse: %x.\n", MouStatus);

        /* Have we successed reading from keyboard? */
        if (NT_SUCCESS(KbdStatus) && KbdStatus != STATUS_PENDING)
        {
            TRACE("KeyboardEvent: %s %04x\n",
                  (KeyInput.Flags & KEY_BREAK) ? "up" : "down",
                  KeyInput.MakeCode);

            /* Set LastInputTick */
            IntLastInputTick(TRUE);

            /* Process data */
            UserEnterExclusive();
            UserProcessKeyboardInput(&KeyInput);
            UserLeave();
        }
        else if (KbdStatus != STATUS_PENDING)
            ERR("Failed to read from keyboard: %x.\n", KbdStatus);
    }
    ERR("Raw Input Thread Exit!\n");
}