bool Host_GetKeyState(int keycode) { #ifdef _WIN32 return (0 != GetAsyncKeyState(keycode)); #elif defined __WXGTK__ std::unique_lock<std::recursive_mutex> lk(main_frame->keystate_lock, std::try_to_lock); if (!lk.owns_lock()) return false; bool key_pressed; if (!wxIsMainThread()) wxMutexGuiEnter(); key_pressed = wxGetKeyState(wxKeyCode(keycode)); if (!wxIsMainThread()) wxMutexGuiLeave(); return key_pressed; #else return wxGetKeyState(wxKeyCode(keycode)); #endif }
void mmCalcValidator::OnChar(wxKeyEvent& event) { if (!m_validatorWindow) return event.Skip(); int keyCode = event.GetKeyCode(); // we don't filter special keys and delete if (keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START) return event.Skip(); wxString str((wxUniChar)keyCode, 1); if (!(wxIsdigit(str[0]) || wxString("+-.,*/ ()").Contains(str))) { if ( !wxValidator::IsSilent() ) wxBell(); return; // eat message } // only if it's a wxTextCtrl mmTextCtrl* text_field = wxDynamicCast(m_validatorWindow, mmTextCtrl); if (!m_validatorWindow || !text_field) return event.Skip(); wxChar decChar = text_field->currency_->DECIMAL_POINT[0]; bool numpad_dec_swap = (wxGetKeyState(wxKeyCode(WXK_NUMPAD_DECIMAL)) && decChar != str); if (numpad_dec_swap) str = wxString(decChar); // if decimal point, check if it's already in the string if (str == '.' || str == ',') { const wxString value = text_field->GetValue(); size_t ind = value.rfind(decChar); if (ind < value.Length()) { // check if after last decimal point there is an operation char (+-/*) if (value.find('+', ind + 1) >= value.Length() && value.find('-', ind + 1) >= value.Length() && value.find('*', ind + 1) >= value.Length() && value.find('/', ind + 1) >= value.Length()) return; } } if (numpad_dec_swap) return text_field->WriteText(str); else event.Skip(); }
void mmTransDialog::OnCancel(wxCommandEvent& /*event*/) { #ifndef __WXMAC__ if (object_in_focus_ != itemButtonCancel_->GetId()) { if (wxGetKeyState(wxKeyCode(WXK_ESCAPE))) itemButtonCancel_->SetFocus(); return; } #endif const wxString& RefType = Model_Attachment::reftype_desc(Model_Attachment::TRANSACTION); if (m_new_trx) mmAttachmentManage::DeleteAllAttachments(RefType, m_trx_data.TRANSID); EndModal(wxID_CANCEL); }
void FlyTool::execute() { if (!holderValid()) return; if (!wxTheApp->IsActive() || !view().editorFrame().mapCanvas().HasFocus()) return; if (wxGetKeyState(WXK_SHIFT) || wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT)) return; Renderer::Camera& camera = view().camera(); Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences(); const wxLongLong updateTime = wxGetLocalTimeMillis(); const float interval = static_cast<float>((updateTime - m_lastUpdateTime).ToDouble()); const float distance = interval / 1000.0f * 320.0f; Vec3f direction; if (wxGetKeyState(wxKeyCode(prefs.getKeyboardShortcut(Preferences::CameraMoveForward).key()))) direction += camera.direction(); if (wxGetKeyState(wxKeyCode(prefs.getKeyboardShortcut(Preferences::CameraMoveBackward).key()))) direction -= camera.direction(); if (wxGetKeyState(wxKeyCode(prefs.getKeyboardShortcut(Preferences::CameraMoveLeft).key()))) direction -= camera.right(); if (wxGetKeyState(wxKeyCode(prefs.getKeyboardShortcut(Preferences::CameraMoveRight).key()))) direction += camera.right(); if (!direction.null()) { direction.normalize(); Controller::CameraSetEvent moveEvent; moveEvent.set(camera.position() + distance * direction, camera.direction(), camera.up()); postEvent(moveEvent); } m_lastUpdateTime = updateTime; }
bool NewtonDemos::GetKeyState(int key) const { return wxGetKeyState(wxKeyCode(key & 0xff)); // return m_key[m_keyMap[key & 0xff]] ? true : false; }