I actually came across this dilemma with Xbox Controller Input. Although not EXACTLY the same it's pretty damn similar. You can change the code in my example to suit your needs.
Edit: Your situation would use this ->
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagrawmouse
And you can learn how to create a raw input class via ->
https://docs.microsoft.com/en-us/windows/desktop/inputdev/raw-input
But.. now onto the super awesome algorithm... not really, but hey.. it's pretty cool :)
*So... we can store the states of every button and which are Pressed, Released, and Held Down!!! We can also check Holding Time, but that does require a single if statement and can check any number of buttons, but there are some rules see below for this information.
Obviously if we want to check if something is pressed, released, etc.. you would do "If(This) { }", but this is showing how we can get the press state and then turn it off the next frame so your "ismousepressed" will actually be false the next time you check.
Full Code Here:
https://github.com/JeremyDX/DX_B/blob/master/DX_B/XGameInput.cpp
How it works..
So I'm not sure the values you receive when you depict if a button is pressed or not, but basically when I load in XInput I get a 16bit value between 0 and 65535 this has 15 bits possible states for "Pressed".
The problem was every time I checked this It would simply give me the current state of the information. I needed a way to convert the current state into Pressed, Released, and Hold Values.
So what I did is the following.
First we create a "CURRENT" variable. Every time we check this data we set the "CURRENT" to a "PREVIOUS" variable and then store the new data to "Current" as seen here ->
uint64_t LAST = CURRENT;
CURRENT = gamepad.wButtons;
With this information here's where it get's exciting!!
We can now figure out if a Button is being HELD DOWN!
BUTTONS_HOLD = LAST & CURRENT;
What this does is basically it compares the two values and any button presses that are shown in both will stay 1 and everything else set to 0.
I.e. (1 | 2 | 4) & (2 | 4 | 8) will yield (2 | 4).
Now that we have which buttons are "HELD" down. We can get the rest.
Pressed is simple.. we take our "CURRENT" state and remove any held down buttons.
BUTTONS_PRESSED = CURRENT ^ BUTTONS_HOLD;
Released is the same only we compare it to our LAST state instead.
BUTTONS_RELEASED = LAST ^ BUTTONS_HOLD;
So looking at the Pressed situation. If let's say Currently we had 2 | 4 | 8 pressed. We found that 2 | 4 where held. When we remove the Held Bits we are left with only 8. This is the newly pressed bit for this cycle.
The same can be applied for Released. In this scenario "LAST" was set to 1 | 2 | 4. So when we remove the 2 | 4 bits. We are left with 1. So the button 1 was released since the last frame.
This above scenario is probably the most ideal situation you can offer for bit comparison and it provides 3 levels of data with no if statements or for loops just 3 quick bit calculations.
I also wanted to document hold data so although my situation isn't perfect... what it does is we basically set the holdbits we want to check for.
So every time we set our Press/Release/Hold data we check if the hold data still equals the current hold bit check. If it doesn't we reset it's time to current time. In my case I'm setting it to frame indexes so I know how many frames it's been held down for.
The downside to this approach is I can't get individual hold times, but you can check multiple bits at once. I.e. if I set the hold bit to 1 | 16 if either 1 or 16 are not held this would fail. So it requires that ALL those buttons are held down to continue ticking.
Then if you look in the code you'll see all the neat function calls.
So your example would be reduced to simply checking if a button press occurred and a button press can only occur once with this algorithm. On the next check to press it will not exist since you can't press more then once you'd have to release before you can press again.