Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Perform action at timed intervals when holding key down
QtWS25 Last Chance

Perform action at timed intervals when holding key down

Scheduled Pinned Locked Moved Unsolved General and Desktop
keysmediaplayertimer
4 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JordanHarris
    wrote on last edited by
    #1

    I'm creating a media player using Qt and libvlc (VLC-Qt) and I want to add fast-forward and rewind functionality when a key is held down (such as left/right arrow keys or media forward/backward keys). I'm thinking that I should set the position of the media to increase/decrease by some fixed amount at a timed interval when a key is held down, but perform some other action when it's just pressed (like go to next media in library/playlist). Has anyone done something like this before, or does anyone have any ideas? Perhaps Qt provides a solution for this type of thing already? Any help would be greatly appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use a QTimer that will timeout after a certain amount of time and trigger the slot that will do the move the way you want it. You can start it by reimplementing keyPressEvent and stop it from keyReleaseEvent.

      Hope it helps.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JordanHarris
        wrote on last edited by
        #3

        @SGaist said:

        Hi,

        You can use a QTimer that will timeout after a certain amount of time and trigger the slot that will do the move the way you want it. You can start it by reimplementing keyPressEvent and stop it from keyReleaseEvent.

        Hope it helps.

        Ahh, I didn't really think about stopping the timer on the keyReleaseEvent. Thank you very much. I guess I could just see how much time has passed between the press and the release to determine if it was just pressed or if it was held down. Thank you for your response. I think I should be able to accomplish this.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's what the timer is for. If you press the key long enough then it will fire but if you release it quicker that the timeout, the timer will be cancelled, no need to measure the time between both events.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved