Download

Return the Timing of Multiple Inputs Sent during a Tick

Is there a way to return the timing of multiple inputs sent by a player during a tick? Basically what I want to do is add an impulse to an actor with a velocity based on how fast one scrolls the mouse wheel.

The axis pin from the mouse wheel axis event blueprint node gives me how many mouse wheel events occurred between ticks but this isn’t enough resolution to give enough different velocity reactions. Instead I want the timing between two mouse wheel events (down to the millisecond in the case of a mouse with 1000 Hz polling rate). I’m assuming this isn’t possible through blueprint scripting so I’m posting this in the C++ forum, but if it is that would be even better.

Is this possible with the UE4 API in C++? If so would it be hard to implement and how would I go about it? My only previous coding experience is in scripting languages like Python but I have managed to pick up on enough of the C++ syntax that I think I could give this a go if it isn’t too hard and given some direction.

If not possible, or it would be hard, I did cobble together some C++ code that does this independent of UE4 using Windows API calls. Probably not the best solution but I was thinking one possibility is to independently run this as a separate exe simultaneous to my UE4 game and have the exe print out results to a text file that the UE4 game could read. Seems like a bit of a kludge and not sure if that will have too much lag though.

If anyone has thoughts on this I’d appreciate any help, thanks.

I’m following up on this thread in case anyone else ends up here through a search and this sounds similar to something you want to do. I took the summer off from this project but picked it up again about a week ago. I’ve got it working now, printing my input timings in UE4 anyway, so I should be good to go and can use blueprint scripting to turn that into meaningful impulse velocities for the actors.

I ended up using the Windows API calls but rather than the kludge idea of separate programs, I created a DLL out of it and linked it to my UE4 project.

This article was very useful in doing that: https://wiki.unrealengine.com/Linking_Dlls The linking itself wasn’t bad. The only challenge was figuring out how to get my C++ vector output from the DLL into a TArray in UE4 since there wasn’t a specific example of that in the tutorial.

I got really stuck a couple times though with making the code I had working in a console app work in a DLL instead. I did not understand how the code that hooks the mouse input works. Still don’t fully but a little better now. The biggest problem turned out to be an empty while loop to keep the hook set until a specified condition was true. That worked in a console app but not in a DLL. When I gave the while loop something meaningless to do it worked. After a bit more searching I found I could have it empty if I defined the condition variable of the while loop as volatile. I also had problems with UE4 crashing after freeing the DLL and that turned out to be because my Unhook function was not getting called before the DLL was freed.

I think I’ve learned enough to actually be somewhat helpful so I’ll stay subscribed to this thread if anybody happens upon it with any questions.