10/28/2023 0 Comments Check if key is held down roblox![]() Some libraries may use threading behind the scenes, but you do not have to create any threads for this. You just need to be able to know if a key is held down or not. M_Tetris->MoveFigureLeft() // then repeating discretelyĪFAIK not all keyboards supports multiple key presses at once or implement it not quite correctly. If ( IsKeyPressedRepeatable(VK_LEFT, dt) ) // Move figure in Tetris. If ( IsKeyPressedOnce(VK_Space)) // Jump once per Spacebar press If ( m_bPressedKeys ) // Go to menu once per press M_Player.Move( m_Player.GetSpeed() * dt, 0 ) // dx, dy Usage example: if ( m_bPressedKeys ) // Just move player continuously every frame while key is pressed If ( m_KeyRepeatTimer >= m_KeyRepeatInterval ) If (m_KeyDelayTimer >= m_KeyDelayInterval) dt - is a delta time between game frames every `KeyDelayInterval` seconds (or your time units). ![]() returns true once, then after `KeyDelayTimer` seconds and repeats LockKey(key) // Prevent key from pressing next frames until releasedīool IsKeyPressedRepeatable( const int& key, const float& dt ) You can use arrays OR accessors like thisīool KeyDown(const unsigned int& key) const īool IsKeyPressed( const int& key ) // returns true only once per press Memcpy(&m_bPressedKeysPrev, &m_bPressedKeys, sizeof(bool)*256) GetKeyboardState(pKeyBuffer) // Change this for non-Windows platforms ZeroMemory( pKeyBuffer, sizeof( UCHAR ) * 256 ) (adapted from some books for newbies): bool m_bPressedKeys // array of pressed keys current frameīool m_bPressedKeysPrev // previous frame Not sure it is perfect or exaсtly what you looking for and its for single-player, but try something like that
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |