Go Down

Topic: Help with mouse input and output? (Read 7525 times) previous topic - next topic

weird_dave

Simplest option would be to create a random offset after each toggle and add that to the Rate, 1 line changes slightly and another is added:
Code: [Select]
if (millis() - ClickTime >= Rate + RandOffset) {
 RandOffset = random(20);

But I wouldn't worry about this yet, get the basics working otherwise you'll end up with a huge bunch of code which doesn't work and won't have a clue where to start debugging it.

David1937

#31
Jan 16, 2017, 12:31 am Last Edit: Jan 16, 2017, 05:58 am by David1937
Simplest option would be to create a random offset after each toggle and add that to the Rate, 1 line changes slightly and another is added:
Code: [Select]
if (millis() - ClickTime >= Rate + RandOffset) {
 RandOffset = random(20);

But I wouldn't worry about this yet, get the basics working otherwise you'll end up with a huge bunch of code which doesn't work and won't have a clue where to start debugging it.
I think I found a USB mouse code on GitHUB but you are the master at this so I don't know if it will work. Will using this: https://github.com/dalelyunas/ArduinoMouse/blob/master/ArduinoMouse.ino work? Is it better and/or easier than using the other method?

David1937

#32
Jan 16, 2017, 12:43 am Last Edit: Jan 16, 2017, 05:59 am by David1937
Simplest option would be to create a random offset after each toggle and add that to the Rate, 1 line changes slightly and another is added:
Code: [Select]
if (millis() - ClickTime >= Rate + RandOffset) {
 RandOffset = random(20);

But I wouldn't worry about this yet, get the basics working otherwise you'll end up with a huge bunch of code which doesn't work and won't have a clue where to start debugging it.
On a side note, I am kinda getting sick of asking questions and stuff.

Is there any other microcontroller device or combination, I don't care the brand, that would make this any easier? Or would I still be in the same situation?

weird_dave

That mouse code will probably work, but it's for reading the mouse, which is already solved with Due specific code. I'm definitely not a master at this :D

There is other hardware out there for sure. You could even use 2 Dues, one to read the mouse and the other to be a mouse, both then use their own Native USB ports (one as a host for the real USB mouse, the other a client to be the fake mouse connected to the PC), a simple serial connection (2 wires, 1 way comms) would transfer the mouse info between them. Or get a USB shield, there are many solutions to the problem. Personally I'd use software until the anticheat breaks it. I think I stumbled upon some python code to emulate a mouse recently, you could use C++ or even assembly. But then again, I enjoy this sort of thing, so finding new ways to solve the problem when the old solution breaks interests me :)

The inline hardware solution will pretty much work for all time, but the game experience quality will depend on how good the hardware and its software is, the PC software solution should be much easier to get a good experience with since there's no interception of the movement.

David1937

That mouse code will probably work, but it's for reading the mouse, which is already solved with Due specific code. I'm definitely not a master at this :D

There is other hardware out there for sure. You could even use 2 Dues, one to read the mouse and the other to be a mouse, both then use their own Native USB ports (one as a host for the real USB mouse, the other a client to be the fake mouse connected to the PC), a simple serial connection (2 wires, 1 way comms) would transfer the mouse info between them. Or get a USB shield, there are many solutions to the problem. Personally I'd use software until the anticheat breaks it. I think I stumbled upon some python code to emulate a mouse recently, you could use C++ or even assembly. But then again, I enjoy this sort of thing, so finding new ways to solve the problem when the old solution breaks interests me :)

The inline hardware solution will pretty much work for all time, but the game experience quality will depend on how good the hardware and its software is, the PC software solution should be much easier to get a good experience with since there's no interception of the movement.
Sorry, I am kinda of confused by this and by the research I have been doing.

So if I were to understand you correctly if I were to use a USB host shield (or even two due's not doing that though :p lol) with the Due I wouldn't need to make all that emulation code?

What solution (buying more things or not) do you think would make it the easiest and best quality? But if the quality is still playable I would like something that would be the easiest solution.

And thanks you are the master if you know all this, seems unbelievable when new people like me join and see you guys with all your knowledge with this stuff. :P

MorganS

#35
Jan 17, 2017, 09:02 am Last Edit: Jan 25, 2017, 07:18 am by MorganS
Assistance withdrawn.
"The problem is in the code you didn't post."

weird_dave

So if I were to understand you correctly if I were to use a USB host shield (or even two due's not doing that though :p lol) with the Due I wouldn't need to make all that emulation code?
You still need to pretend to be a mouse, there's no getting away from that, this just lets you use a USB mouse and a USB port on your PC easily, you simply can't do that with a Due on its own.

What solution (buying more things or not) do you think would make it the easiest and best quality? But if the quality is still playable I would like something that would be the easiest solution.
The in-line method is definitely not the easiest to get right. You never know, anti cheat may eventually block an Arduino mouse from being used. I really would do this purely on the PC first, then when that doesn't work, send commands to the Due to do the clicks.

weird_dave

I've been watching this discussion for a while. I don't understand the need to pass through the mouse at all.
Me neither, I wouldn't do it that way. (until the anticheat software decides otherwise, but there's always a workaround of some kind).

You can plug more than one mouse into your computer. If you have a laptop with a touchpad plus an external mouse, you are doing this all the time. You can make movements with one mouse and clicks with the other. This seems to be a normal way of doing things.
This is one of the methods I mentioned early on, with various options of getting the due to click (switches, serial commands from the PC).

So use a Due (or whatever native-USB Arduino variant you prefer - there's a lot of them now) and have it generate clicks when you push a button on that Due. Keep using your normal mouse like normal, with no modifications. You might like to hot-glue the Due's button on top of your mouse, but that's a minor enhancement.
The problem is activating the button on the due, I mentioned a foot switch in post 15. mounting an extra switch on the mouse isn't really viable for long term battle, the un-ergonomic nature of it will likely cause pain. The OP doesn't want to modify any mice, so re-wiring a spare button to the due isn't an option really either since you'd need to make some holes for the wires. very thin wire might just squash-fit next to the existing cable entry point.

David1937

#38
Jan 17, 2017, 05:31 pm Last Edit: Jan 18, 2017, 05:29 am by David1937
Me neither, I wouldn't do it that way. (until the anticheat software decides otherwise, but there's always a workaround of some kind).
This is one of the methods I mentioned early on, with various options of getting the due to click (switches, serial commands from the PC).
The problem is activating the button on the due, I mentioned a foot switch in post 15. mounting an extra switch on the mouse isn't really viable for long term battle, the un-ergonomic nature of it will likely cause pain. The OP doesn't want to modify any mice, so re-wiring a spare button to the due isn't an option really either since you'd need to make some holes for the wires. very thin wire might just squash-fit next to the existing cable entry point.
Actually I kinda don't mind the option for the foot pedal. What would be the best way that I could use my feet to trigger a quick response. For example, for guns I would have to maybe have the foot pedal rapid-firing for 10 seconds then have to let go for maybe a second to let it reload quickly and then repeat a few times before I don't see anyone anymore or I am dead.

What is a idea that I could use my feet where I wouldn't accidentally press it that often but also holding it down in small spurts and then quickly taking it off? Like would a normal foot pedal be fast enough? What do you think is the best option?

David1937


Me neither, I wouldn't do it that way. (until the anticheat software decides otherwise, but there's always a workaround of some kind).
This is one of the methods I mentioned early on, with various options of getting the due to click (switches, serial commands from the PC).
The problem is activating the button on the due, I mentioned a foot switch in post 15. mounting an extra switch on the mouse isn't really viable for long term battle, the un-ergonomic nature of it will likely cause pain. The OP doesn't want to modify any mice, so re-wiring a spare button to the due isn't an option really either since you'd need to make some holes for the wires. very thin wire might just squash-fit next to the existing cable entry point.
This is just a guess but I was wondering if getting one of those LattePanda mini computers would be a solution to the problem. I could plug the mouse into the mini microcontroller computer and run anything I wanted (you said you found a Python script) and then convey that to my computer.

MorganS

#40
Jan 18, 2017, 06:30 am Last Edit: Jan 25, 2017, 07:18 am by MorganS
Assistance withdrawn.
"The problem is in the code you didn't post."

weird_dave

Actually I kinda don't mind the option for the foot pedal. What would be the best way that I could use my feet to trigger a quick response. For example, for guns I would have to maybe have the foot pedal rapid-firing for 10 seconds then have to let go for maybe a second to let it reload quickly and then repeat a few times before I don't see anyone anymore or I am dead.
Yeah, just set the arduino to rapid fire while it's held. This is by far the simplest hardware solution (there are technically simpler hardware solutions, but this is the Due forum :D )

What is a idea that I could use my feet where I wouldn't accidentally press it that often but also holding it down in small spurts and then quickly taking it off? Like would a normal foot pedal be fast enough? What do you think is the best option?
I still remember being useless with a mouse, but you soon learn. I did program a keyboard key to do mouse clicks once and it became second nature to do it. I don't recall the reason I did it, it may have been a dodgy mouse button, or I didn't want to risk moving the mouse when I clicked.

This is just a guess but I was wondering if getting one of those LattePanda mini computers would be a solution to the problem. I could plug the mouse into the mini microcontroller computer and run anything I wanted (you said you found a Python script) and then convey that to my computer.
The only difference here is you have another PC, you still have the problem of getting the mouse control to your gaming PC. You could use the wifi to do it, you don't even need the built in arduino compatible processor. Of course, this requires something running on the gaming PC to do the mouse control... You could potentially use a software KVM (I use input director all the time) but there will be issues when the mouse hits the wrong edge of the screen and switches to controlling the latte (I run games windowed to avoid this problem, but I have a 40" 4K monitor, so running at a lowly 3200x1800 is still a good experience)

weird_dave

A quick search on ebay suggests a new foot switch can be had for £2.50. I'm tempted to get one myself, I can immediately see how this would transform some games, hitting the jetpack key while WASD/mousing is a pain :D

weird_dave

This might be easier
https://www.amazon.co.uk/gp/product/B008MU0TBU/
If you map the fire button to a key, map the footpedal to that key, job's almost there. 555 timer in the foot pedal to make it autofire when pressed (you could use the Due as a 555, but then you may as well just buy a basic foot switch and hook it up to the arduino anyway).

David1937

How often do you accidentally press any button? I don't think that is a constraint on your design.

Yes a normal foot pedal will be fast enough. Test it by getting a second mouse and putting it on the floor. Tape it down so it doesn't slide. (tape over the optical sensor on the bottom so it can't detect any movement.) It won't have the rapid fire feature but you can test if you like having a pedal.
This might be easier
https://www.amazon.co.uk/gp/product/B008MU0TBU/
If you map the fire button to a key, map the footpedal to that key, job's almost there. 555 timer in the foot pedal to make it autofire when pressed (you could use the Due as a 555, but then you may as well just buy a basic foot switch and hook it up to the arduino anyway).
Yeah now testing it I understand that I will be quick enough. I have never had a foot pedal though so I don't know if they work like this though but since I will be needing to activate it quickly and frequently on and off I would like to be able to rest my foot against it while it's not in use. If you try holding your foot mid air for like more than even 20 seconds your calf begins to get tired real quick.

@weird_dave Yeah I don't really want to do that solution though because I want to be able to have the code sent via mouseclick from the Arduino. That way I can customize the code and be able to send it like I want. All I want to do is while the foot pedal is held the Arduino clicks, which is quite easy in terms of software but I really don't know how to do that hardware wise. I know that it is a simple setup both hardware and software but I don't know how to connect the Arduino to the pedal, I know I need to access the wires but I don't know where or how to plug them into the Arduino.

I found this: http://www.instructables.com/id/Arduino-foot-pedal-PTT-switch/

This is exactly the same thing I need but I need the mouse click code instead of sending a key, which I know is quite easy to change but hardware wise I don't get a few things.

How is the pedal getting power?

Can I use any pedal for this? If so what is the best pedal to use for my use?


Go Up