InputDevice *Input::getDevice(const std::string &name) { //std::cerr << "Input: looking for dev " << name << std::endl; InputDevice *dev = findInMap(drivers, name); if (!dev) { std::string conf = configPath("Device." + name); std::string type = coCoviseConfig::getEntry("driver", conf, "const"); //std::cerr << "Input: creating dev " << name << ", driver " << type << std::endl; DriverFactoryBase *plug = getDriverPlugin(coVRMSController::instance()->isMaster() ? type : "const"); if (!plug) { std::cerr << "Input: replaced driver " << name << " with \"const\"" << std::endl; plug = getDriverPlugin("const"); } if (plug) { dev = plug->newInstance("COVER.Input.Device." + name); drivers[name] = dev; if (dev->needsThread()) dev->start(); } } return dev; }
void AddEditAutoProfileDialog::checkForReservedGUIDs(int index) { QVariant data = ui->devicesComboBox->itemData(index); if (index == 0) { ui->asDefaultCheckBox->setChecked(false); ui->asDefaultCheckBox->setEnabled(false); ui->asDefaultCheckBox->setToolTip(tr("Please use the main default profile selection.")); } else if (!data.isNull()) { InputDevice *device = data.value<InputDevice*>(); if (reservedGUIDs.contains(device->getGUIDString())) { ui->asDefaultCheckBox->setChecked(false); ui->asDefaultCheckBox->setEnabled(false); ui->asDefaultCheckBox->setToolTip(tr("A different profile is already selected as the default for this device.")); } else { ui->asDefaultCheckBox->setEnabled(true); ui->asDefaultCheckBox->setToolTip(tr("Select this profile to be the default loaded for\nthe specified device. The selection will be used instead\nof the all default profile option.")); } } }
int main( int argc, char** argv ) { QApplication app( argc, argv ); InputManager::instance()->initialize(); InputDevice* keyboard = InputManager::instance()->device( "qt_keyboard" ); if( !keyboard ) qFatal( "No keyboard found!" ); InputParameter* parameter = keyboard->parameter( Qt::Key_Return ); if( !parameter ) qFatal( "No return key found!" ); QLabel label; QObject::connect( parameter, &InputParameter::buttonStateChanged, [&]() { label.setText( parameter->buttonState() == InputParameter::ButtonPressed ? "Return Pressed" : "Return Released" ); } ); label.show(); app.exec(); }
void AddEditAutoProfileDialog::saveAutoProfileInformation() { info->setProfileLocation(ui->profileLineEdit->text()); int deviceIndex = ui->devicesComboBox->currentIndex(); if (deviceIndex > 0) { QVariant temp = ui->devicesComboBox->itemData(deviceIndex, Qt::UserRole); // Assume that if the following is not true, the GUID should // not be changed. if (!temp.isNull()) { InputDevice *device = ui->devicesComboBox->itemData(deviceIndex, Qt::UserRole).value<InputDevice*>(); info->setGUID(device->getGUIDString()); info->setDeviceName(device->getSDLName()); } } else { info->setGUID("all"); info->setDeviceName(""); } info->setExe(ui->applicationLineEdit->text()); info->setWindowClass(ui->winClassLineEdit->text()); info->setWindowName(ui->winNameLineEdit->text()); info->setDefaultState(ui->asDefaultCheckBox->isChecked()); //info->setActive(true); }
int InputManager::checkForNewXInputDevices() { DWORD dwResult; XINPUT_STATE state; int nrOfControllersAdded = 0; for(int i = nrOfXInputDevices_; i < XUSER_MAX_COUNT; i++) { dwResult = 0; ZeroMemory(&state, sizeof(XINPUT_STATE)); dwResult = XInputGetState(i, &state); if(dwResult == ERROR_SUCCESS) { GUID guid; ZeroMemory(&guid, sizeof(guid)); InputDevice* device = new XInputDevice(nrOfXInputDevices_++, guid, "Xbox Controller (non DI)", devices_.size()); nrOfControllersAdded++; devices_.push_back(device); SEND_EVENT(&Event_CreateInputDevice(device, device->getInputObjectArray())); } } return nrOfControllersAdded; }
void InputManager::processEvent( const InputEvent& event ) { for( size_t i = 0; i < devices.size(); i++ ) { InputDevice* device = devices[i]; device->processEvent( event ); } }
Result::Name CDIForceFeedbackEffectImpl::OnInputDevicePlugged() { InputDevice *pInputDevice = GetTargetInputDevice(); if( pInputDevice ) return pInputDevice->InitForceFeedbackEffect( *this ); else return Result::UNKNOWN_ERROR; }
/** Get the key bound to a player action (enum GUI::PlayerAction)*/ std::string getKeyBinding(int Enum_value) { InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice(); DeviceConfig* config = device->getConfiguration(); PlayerAction ScriptAction = (PlayerAction)Enum_value; irr::core::stringw control = config->getBindingAsString(ScriptAction); std::string key = StringUtils::wideToUtf8(control); return key; }
int main () { InputDevice* scanner = new InputDevice("Scanner"); cout << scanner->getName(); Device* printScanDev = new IODevice("PrintScan"); printScanDev->connectToCPU(); return 0; }
Keyboard* InputManager::getKeyboard() const { for( size_t i = 0; i < devices.size(); i++ ) { InputDevice* device = devices[i]; if( device->getType() == InputDeviceType::Keyboard ) return static_cast<Keyboard*>( device ); } return nullptr; }
Mouse* InputManager::getMouse() const { for( size_t i = 0; i < devices.size(); i++ ) { InputDevice* device = devices[i]; if( device->getType() == InputDeviceType::Mouse ) return static_cast<Mouse*>( device ); } return nullptr; }
void JoyAxis::joyEvent(int value, bool ignoresets) { setCurrentRawValue(value); //currentRawValue = value; bool safezone = !inDeadZone(currentRawValue); currentThrottledValue = calculateThrottledValue(value); if (this->stick) { if (safezone && !isActive) { isActive = eventActive = true; emit active(value); } else if (!safezone && isActive) { isActive = eventActive = false; emit released(value); } stick->joyEvent(ignoresets); } else { InputDevice *device = parentSet->getInputDevice(); if (!device->isGameController() && !device->hasCalibrationThrottle(index)) { performCalibration(currentRawValue); safezone = !inDeadZone(currentRawValue); currentThrottledValue = calculateThrottledValue(value); } if (safezone && !isActive) { isActive = eventActive = true; emit active(value); createDeskEvent(ignoresets); } else if (!safezone && isActive) { isActive = eventActive = false; emit released(value); createDeskEvent(ignoresets); } else if (isActive) { createDeskEvent(ignoresets); } } emit moved(currentRawValue); }
Result::Name CDIForceFeedbackEffectImpl::Init( const CForceFeedbackEffectDesc& desc, const CForceFeedbackTargetDevice& target ) { m_pDesc = desc.CreateCopy(); m_Target = target; InputDevice *pInputDevice = GetTargetInputDevice(); if( pInputDevice ) return pInputDevice->InitForceFeedbackEffect( *this ); else return Result::UNKNOWN_ERROR; }
void InputDaemon::refreshIndexes() { for (int i = 0; i < SDL_NumJoysticks(); i++) { SDL_Joystick *joystick = SDL_JoystickOpen(i); SDL_JoystickID joystickID = SDL_JoystickInstanceID(joystick); InputDevice *tempdevice = joysticks->value(joystickID); if (tempdevice) { tempdevice->setIndex(i); } } }
void coInputTUI::updateTUI() { if (size_t(personsChoice->getNumEntries()) != Input::instance()->getNumPersons()) { personsChoice->clear(); for (size_t i = 0; i < Input::instance()->getNumPersons(); i++) { personsChoice->addEntry(Input::instance()->getPerson(i)->getName()); } } int activePerson = Input::instance()->getActivePerson(); if(activePerson != personsChoice->getSelectedEntry()) personsChoice->setSelectedEntry(activePerson); if (size_t(bodiesChoice->getNumEntries()) != Input::instance()->getNumBodies()) { const std::string body = bodiesChoice->getSelectedText(); bodiesChoice->clear(); for (size_t i = 0; i < Input::instance()->getNumBodies(); i++) { bodiesChoice->addEntry(Input::instance()->getBody(i)->getName()); } bodiesChoice->setSelectedEntry(0); bodiesChoice->setSelectedText(body); } TrackingBody * tb = Input::instance()->getBody(bodiesChoice->getSelectedEntry()); if(tb) { osg::Matrix m = tb->getOffsetMat(); osg::Vec3 v = m.getTrans(); coCoord coord = m; for (int i = 0; i < 3; i++) { bodyTrans[i]->setValue(v[i]); bodyRot[i]->setValue(coord.hpr[i]); } } InputDevice *id = Input::instance()->getDevice(devicesChoice->getSelectedEntry()); if(id) { osg::Matrix m = id->getOffsetMat(); osg::Vec3 v = m.getTrans(); coCoord coord = m; for (int i = 0; i < 3; i++) { deviceTrans[i]->setValue(v[i]); deviceRot[i]->setValue(coord.hpr[i]); } } }
// get device name static std::string getDeviceName(int id) { std::map<int, std::string>::const_iterator search = g_device.find(id); if (search != g_device.end()) { return search->second; } InputDevice device = InputDevice::getDevice(id); std::string name = device.getName(); g_device[id] = name; return name; }
void InputComponent::handleRumbleEvent(Event_Rumble* e) { InputDevice* device = inputManager_->GetDevice(e->deviceNr); if(device != nullptr) { if(e->runRumble) device->RunForceFeedback(e->duration); else device->StopForceFeedback(); device->SetForceFeedback(e->leftScale, e->rightScale); } }
void InputDaemon::refreshIndexes() { for (int i = 0; i < SDL_NumJoysticks(); i++) { SDL_Joystick *joystick = SDL_JoystickOpen(i); SDL_JoystickID joystickID = SDL_JoystickInstanceID(joystick); // Make sure to decrement reference count SDL_JoystickClose(joystick); InputDevice *tempdevice = joysticks->value(joystickID); if (tempdevice) { tempdevice->setIndex(i); } } }
void SDLEventReader::closeDevices() { if (sdlIsOpen) { if (joysticks) { QMapIterator<SDL_JoystickID, InputDevice*> iter(*joysticks); while (iter.hasNext()) { iter.next(); InputDevice *current = iter.value(); current->closeSDLDevice(); } } } }
void JoyAxis::performCalibration(int value) { InputDevice *device = parentSet->getInputDevice(); if (value <= -30000) { // Assume axis is a trigger. Set default throttle to Positive. device->setCalibrationThrottle(index, PositiveThrottle); } else { // Ensure that default throttle is used when a device is reset. device->setCalibrationThrottle(index, (JoyAxis::ThrottleTypes)throttle); } //else if (value >= -15000 && value <= 15000) //{ // device->setCalibrationThrottle(index, NormalThrottle); //} }
bool Program::update() { InputDevice mouse = window.get_ic().get_mouse(); float time = System::get_time() / 1000.0f; uniforms.time = time; uniforms.mouse = Vec4f(mouse.get_x() / 800.0f, mouse.get_y() / 600.0f, 0, 0); for(int i=0; i< uniforms.xparticle_count; ++i) { uniforms.positions[i].x += sinf(time + i * 2.0f) / 40.0f; uniforms.positions[i].y += cosf(time + i * 2.0f) / 40.0f; } uniformVector.upload_data(gc, &uniforms, 1); effect.draw(gc); window.flip(0); return !exit; }
void InputDeviceProvider_Win32Hid::update(InputDevice &joystick, RAWINPUT *raw_input) { auto previous_buttons = buttons; auto previous_axis = axis_values; //auto previous_hat = hat_values; // TODO: What about this if (raw_input->header.hDevice == rawinput_device) { DataBuffer preparse_data = get_preparse_data(); for (DWORD i = 0; i < raw_input->data.hid.dwCount; i++) { BYTE *raw_data = const_cast<BYTE *>(raw_input->data.hid.bRawData); DWORD offset = i * raw_input->data.hid.dwSizeHid; void *report = raw_data + offset; int report_size = raw_input->data.hid.dwSizeHid; update(preparse_data.get_data(), report, report_size); } } for (unsigned int cnt = 0; cnt < previous_buttons.size(); cnt++) { if (previous_buttons[cnt] != buttons[cnt]) { InputEvent input_event; input_event.type = buttons[cnt] ? InputEvent::pressed : InputEvent::released; input_event.id = (InputCode) cnt; buttons[cnt] ? joystick.sig_key_down()(input_event) : joystick.sig_key_up()(input_event); } } for (unsigned int cnt = 0; cnt < previous_axis.size(); cnt++) { if (previous_axis[cnt] != axis_values[cnt]) { InputEvent input_event; input_event.type = InputEvent::axis_moved; input_event.id = (InputCode) cnt; input_event.axis_pos = axis_values[cnt]; joystick.sig_axis_move()(input_event); } } }
void SetJoystick::refreshAxes() { deleteAxes(); InputDevice *device = getInputDevice(); for (int i=0; i < device->getNumberRawAxes(); i++) { JoyAxis *axis = new JoyAxis(i, index, this, this); axes.insert(i, axis); if (device->hasCalibrationThrottle(i)) { JoyAxis::ThrottleTypes throttle = device->getCalibrationThrottle(i); axis->setInitialThrottle(throttle); } enableAxisConnections(axis); } }
void DataDeviceManager::overrideSelection(const QMimeData &mimeData) { QStringList formats = mimeData.formats(); if (formats.isEmpty()) return; m_retainedData.clear(); foreach (const QString &format, formats) m_retainedData.setData(format, mimeData.data(format)); m_compositor->feedRetainedSelectionData(&m_retainedData); m_compositorOwnsSelection = true; InputDevice *dev = m_compositor->defaultInputDevice(); Surface *focusSurface = dev->keyboardFocus(); if (focusSurface) offerFromCompositorToClient( dev->dataDevice(focusSurface->base()->resource.client)->dataDeviceResource()); }
void SDLEventReader::closeSDL() { SDL_Event event; QMapIterator<SDL_JoystickID, InputDevice*> iter(*joysticks); while (iter.hasNext()) { iter.next(); InputDevice *current = iter.value(); current->closeSDLDevice(); } // Clear any pending events while (SDL_PollEvent(&event) > 0) { } SDL_Quit(); sdlIsOpen = false; emit sdlClosed(); }
void InputRecorder::Start() { isRecording_ = true; if (recording_) { recording_->Clear(); } else { recording_ = manager_.GetAllocator().New<InputRecording>(manager_.GetAllocator()); } startTime_ = manager_.GetTime(); recordingListener_ = manager_.GetAllocator().New<RecordingListener>(manager_, *this); recordingListenerId_ = manager_.AddListener(recordingListener_); // Record the initial state for (InputManager::iterator it = manager_.begin(); it != manager_.end(); ++it) { InputDevice* device = it->second; const DeviceId deviceId = device->GetDeviceId(); if (!IsDeviceToRecord(deviceId)) { continue; } GAINPUT_ASSERT(device->GetInputState()); for (DeviceButtonId buttonId = 0; buttonId < device->GetInputState()->GetButtonCount(); ++buttonId) { if (device->IsValidButtonId(buttonId)) { if (device->GetButtonType(buttonId) == BT_BOOL) { recording_->AddChange(0, deviceId, buttonId, device->GetBool(buttonId)); } else { recording_->AddChange(0, deviceId, buttonId, device->GetFloat(buttonId)); } } } } }
bool Program::update() { GraphicContext gc = window.get_gc(); InputDevice mouse = window.get_ic().get_mouse(); float time = System::get_time() / 1000.0f; uniforms.time = time; auto pos = mouse.get_position(); uniforms.mouse = Vec4f(pos.x / 800.0f, pos.y / 600.0f, 0, 0); for(int i=0; i< uniforms.particle_count; ++i) { uniforms.positions[i].x += sinf(time + i * 2.0f) / 40.0f; uniforms.positions[i].y += cosf(time + i * 2.0f) / 40.0f; } uniformVector.upload_data(gc, &uniforms, 1); effect.draw(gc); window.flip(1); return !exit; }
void coInputTUI::tabletEvent(coTUIElement *tUIItem) { if(tUIItem == personsChoice) { Input::instance()->setActivePerson(personsChoice->getSelectedEntry()); } else if(tUIItem == bodiesChoice) { updateTUI(); } else if(tUIItem == devicesChoice) { updateTUI(); } else if(tUIItem == bodyTrans[0] || tUIItem == bodyTrans[1] || tUIItem == bodyTrans[2] || tUIItem == bodyRot[0] || tUIItem == bodyRot[1] || tUIItem == bodyRot[2]) { TrackingBody * tb = Input::instance()->getBody(bodiesChoice->getSelectedEntry()); osg::Matrix m; MAKE_EULER_MAT(m, bodyRot[0]->getValue(), bodyRot[1]->getValue(), bodyRot[2]->getValue()); osg::Matrix translationMat; translationMat.makeTranslate(bodyTrans[0]->getValue(), bodyTrans[1]->getValue(), bodyTrans[2]->getValue()); m.postMult(translationMat); tb->setOffsetMat(m); } else if(tUIItem == deviceTrans[0] || tUIItem == deviceTrans[1] || tUIItem == deviceTrans[2] || tUIItem == deviceRot[0] || tUIItem == deviceRot[1] || tUIItem == deviceRot[2]) { InputDevice *id = Input::instance()->getDevice(devicesChoice->getSelectedEntry()); osg::Matrix m; MAKE_EULER_MAT(m, deviceRot[0]->getValue(), deviceRot[1]->getValue(), deviceRot[2]->getValue()); osg::Matrix translationMat; translationMat.makeTranslate(deviceTrans[0]->getValue(), deviceTrans[1]->getValue(), deviceTrans[2]->getValue()); m.postMult(translationMat); id->setOffsetMat(m); } }
bool InputManager::addNewDevice(HWND hWindow, GUID instanceGUID, GUID productGUID, std::string name) { bool deviceAdded = false; InputDevice* device; if(nrOfXInputDevices_ >= XUSER_MAX_COUNT || !isXInputDevice(&productGUID)) { LPDIRECTINPUTDEVICE8 dInputDevice; HRESULT result = dInput_->CreateDevice(instanceGUID, &dInputDevice, NULL); if(FAILED(result)) return false; DirectInputDevice* diDevice = new DirectInputDevice(dInputDevice, instanceGUID, name, devices_.size()); if(diDevice->Init(hWindow)) { devices_.push_back(diDevice); device = diDevice; deviceAdded = true; } } else { device = new XInputDevice(nrOfXInputDevices_++, instanceGUID, name, devices_.size()); devices_.push_back(device); deviceAdded = true; } if(deviceAdded) { SEND_EVENT(&Event_CreateInputDevice(device, device->getInputObjectArray())); } return deviceAdded; }
/*! * Sets the backbuffer for this surface. The back buffer is not yet on * screen and will become live during the next swapBuffers(). * * The backbuffer represents the current state of the surface for the * purpose of GUI-thread accessible properties such as size and visibility. */ void Surface::setBackBuffer(SurfaceBuffer *buffer) { m_buffer = buffer; if (m_buffer) { bool valid = m_buffer->waylandBufferHandle() != 0; setSize(valid ? m_buffer->size() : QSize()); m_damage = m_damage.intersected(QRect(QPoint(), m_size)); emit m_waylandSurface->damaged(m_damage); } else { InputDevice *inputDevice = m_compositor->defaultInputDevice(); if (inputDevice->keyboardFocus() == this) inputDevice->setKeyboardFocus(0); if (inputDevice->mouseFocus() && inputDevice->mouseFocus()->surface() == waylandSurface()) inputDevice->setMouseFocus(0, QPointF(), QPointF()); } m_damage = QRegion(); }