Arduino Forum

Products => Arduino Due => Topic started by: David1937 on Jan 04, 2017, 07:41 pm

Title: Help with mouse input and output?
Post by: David1937 on Jan 04, 2017, 07:41 pm
So basically what I am trying to achieve and why I bought the Arduino at least the main purpose that is was to have the mouse plugged into it and then while I push down the Left Mouse Button on the mouse it sends rapid fire mouse clicks to the game (Call of Duty) on my computer. Basically I thought this would make it look like the mouse is clicking from the actual mouse, and I understand the code libarary since the Due can use USBHost which means it has the getButtonStatus which in theory will work?

I literally just ordered the Arduino Due, will this board achieve this small problem?
Title: Re: Help with mouse input and output?
Post by: westfw on Jan 05, 2017, 12:12 am
You need two USB ports; one a USB Host to attach your mouse, and one a USB device to connect to your computer.
In theory this should be possible; the "programming port" should be usable as a device port.  But I'm not sure that the mouse/etc libraries for Due are set up to use that - the more common case would be to use the "USB Native" port for the direct connection to PC *or* a device...

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 05, 2017, 04:27 am
So when using the board on a PC for non-programming purposes you plug it into the "Native USB Port".

Would some sort of splitter or USB hub work around this if there is no other way?

I found this, does it mean that I cannot do it:? http://forum.arduino.cc/index.php?topic=248226.0

I literally just ordered this board for this purpose and I thought that it was the right thing for it? Hopefully can find a way around it if it doesn't work.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 05, 2017, 10:18 am
Blasted forum, I had written a longer reply, but submission failed and I lost it! Here's a short version.

Is your intention to have 1 mouse and pipe all the controls to the PC? I wouldn't do it this way. In fact, I wouldn't even use an arduino unless I needed extra functions that couldn't be mapped to a keyboard easily. Rapid fire of the Left Mouse Button can be mapped to key on the PC keyboard using autoit:
https://www.autoitscript.com/site/ (https://www.autoitscript.com/site/)
Do you have 'extra' mouse buttons? mapping to these is feasible. You could map directly to the left mouse but it's trickier and you need a key to disable the function otherwise you'll be having fun in the game menus.

There are some options for using the Arduino, you could connect a mouse to the native port then emulate a serial mouse via the programming COM port. This could be quite involved. You'll need a button on the Due to enable/disable the function as well.
You could also use mouse emulation and connect it as a 2nd mouse. Either control the rapid fire with a button on the Due or send commands to the due via the programming COM port which then tell the Due to rapid fire. An autoit script could map a key or mouse button to the sending of the command to the Due. I'm not sure if you could map the left mouse button for this as you'd have the real mouse button held down and the Due 'mouse' rapid firing, I suspect this wouldn't work.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 05, 2017, 07:01 pm
See, using autohotkey/autoit is a great idea in theory and I have used that before for other small games and I do have a fair amount of knowledge about it. The reason I would prefer to use the Arduino is because it's an external device so it would appear to the computer as if it's coming from the actual mouse. The thing with software on these types of games nowadays is that the Anti-Cheat on games scans through the memory and all the files on your PC. So using software is not a good option for me, basically defeats the purpose why I got the arduino.

So are you saying that the issue with my design is that I couldn't do it with the left mouse button behind held down because that is what is clicking? So it would be better to do it off a side button on my mouse or something???

This is the code I prepared for it but since but Arduino hasn't come in yet, I don't know if it will work: while(mouse.getButton(LEFT_BUTTON)) {

loopNumber = random(x, y) //number of times clicks before stops


for (int x = 1; x > loopNumber; x++) {

if (!mouse.getButton(LEFT_BUTTON)){     
       break;
    } 
Mouse.press(MOUSE_LEFT);
delay(random(minDelay, maxDelay));
Mouse.release(MOUSE_LEFT);
delay(random(minDelay, maxDelay));
  if (!mouse.getButton(LEFT_BUTTON)){     
       break;
    } 
}


Thanks for the help.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 06, 2017, 01:16 am
See, using autohotkey/autoit is a great idea in theory and I have used that before for other small games and I do have a fair amount of knowledge about it. The reason I would prefer to use the Arduino is because it's an external device so it would appear to the computer as if it's coming from the actual mouse. The thing with software on these types of games nowadays is that the Anti-Cheat on games scans through the memory and all the files on your PC. So using software is not a good option for me, basically defeats the purpose why I got the arduino.

So are you saying that the issue with my design is that I couldn't do it with the left mouse button behind held down because that is what is clicking? So it would be better to do it off a side button on my mouse or something???

This is the code I prepared for it but since but Arduino hasn't come in yet, I don't know if it will work: while(mouse.getButton(LEFT_BUTTON)) {

loopNumber = random(x, y) //number of times clicks before stops


for (int x = 1; x > loopNumber; x++) {

if (!mouse.getButton(LEFT_BUTTON)){     
       break;
    } 
Mouse.press(MOUSE_LEFT);
delay(random(minDelay, maxDelay));
Mouse.release(MOUSE_LEFT);
delay(random(minDelay, maxDelay));
  if (!mouse.getButton(LEFT_BUTTON)){     
       break;
    } 
}


Thanks for the help.

Not like remapping the rapid fire button to the left click is the biggest priorotiy here but what I basically am trying to achieve is to have the mouse plugged into whereever, doesn't really matter where, but I am assuming it has to be plugged into the Due to get information on the mouse. Preferlly the left mouse button (but like I said, that isn't the biggest issue), but as a button is held down I want the Due to send clicks to the PC and as soon as the button is released stop. I appreciate your long answer as although I do know a fair bit about the code and such already, I literally know nothing about the Arduinos and their coponents and in fact the Due is coming in during the next couple of days.

Now that I think of it back in the day maybe a few years ago I used a script back in the day with AutoIt and it indeed did use the left mouse button being held down to produce the clicks. It really does suck because with the insane advance of Anti-Cheat's in competitive games you can't use software at all anymore even if it is external which is one of the main reason I got the Arduino like I said. This was the only option that would be easy to handle as the only other option that wouldn't be detected by the anti cheat was to take another mouse,  and somehow make it click by accessing the mouses Hardware.

I really do appreciate the help though, as I am new to this and don't really understand much and really want to make this as it was the whole reason I bought this thing. @weird_dave
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 06, 2017, 11:38 am
If anti-cheat is an issue with using autoit to generate the mouseclicks [I have seen anticheat stop the use of controlclick() but not yet mouseclick() ] then I would probably use autoit to send a control to the Arduino via USB COM port to do rapid fire, pretending to be a 2nd mouse via the Native USB. You'd probably still need to use a spare keyboard key or extra mouse button to trigger autoit to send the command to the Arduino rather than the left mouse button, but you can always try it and see what happens :)
I'd do this in stages, hook up a button to the due and get it doing mouseclicks as a 2nd mouse, then move on to serial comms and mapping to a key/button. Finally, I'd then implement the rapid fire on the due.
I would be surprised if the anticheat was unhappy with a script that didn't interact with any game binded keys, if it does then the only options left are to use a button on the arduino to do the rapidfire as a 2nd mouse, which is probably inconvenient, or, plug a mouse into the Due Native USB and forward all the movements to the PC as a serial mouse via the USB COM port. This may not be easy. You won't be able to plug the PC and mouse into the Native USB port and use something along the lines of the code you posted as this would require the port being a host and slave simultaneously and the PC would also see the mouse. The programming USB (COM) port can't be used as a generic USB device.

I may have a go at this myself at some point, there are times when 'hardware macros' do work better :D (the autoit/Due version, not the in-line method, too crazy for me :) )

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 06, 2017, 10:43 pm
If anti-cheat is an issue with using autoit to generate the mouseclicks [I have seen anticheat stop the use of controlclick() but not yet mouseclick() ] then I would probably use autoit to send a control to the Arduino via USB COM port to do rapid fire, pretending to be a 2nd mouse via the Native USB. You'd probably still need to use a spare keyboard key or extra mouse button to trigger autoit to send the command to the Arduino rather than the left mouse button, but you can always try it and see what happens :)
I'd do this in stages, hook up a button to the due and get it doing mouseclicks as a 2nd mouse, then move on to serial comms and mapping to a key/button. Finally, I'd then implement the rapid fire on the due.
I would be surprised if the anticheat was unhappy with a script that didn't interact with any game binded keys, if it does then the only options left are to use a button on the arduino to do the rapidfire as a 2nd mouse, which is probably inconvenient, or, plug a mouse into the Due Native USB and forward all the movements to the PC as a serial mouse via the USB COM port. This may not be easy. You won't be able to plug the PC and mouse into the Native USB port and use something along the lines of the code you posted as this would require the port being a host and slave simultaneously and the PC would also see the mouse. The programming USB (COM) port can't be used as a generic USB device.

I may have a go at this myself at some point, there are times when 'hardware macros' do work better :D (the autoit/Due version, not the in-line method, too crazy for me :) )


What do you mean by sending commands? Serial?

This anti-cheat is insane, it literally scans through what you are running with your ram. Macros are a big think in competative Call of Duty, so I am just afraid that since AutoHotkey/AutoIt is such a popular method of making macros, that it will be picked up or picked up as a even a cheat.

I am pretty new at this stuff which kind sucks and limits me on what I wanna do.
Title: Re: Help with mouse input and output?
Post by: westfw on Jan 07, 2017, 02:28 am
You could probably use a PS/2 mouse with a Due and USB computer port.  And a lot of mice still have PS/2 support built in, I think.  Or the other way around.  Or all PS/2 if your computer still has PS/2 ports.   Or all PS/2 on the Arduino, with an external commercial PS/2 to USB adapter.

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 08, 2017, 12:36 am
If anti-cheat is an issue with using autoit to generate the mouseclicks [I have seen anticheat stop the use of controlclick() but not yet mouseclick() ] then I would probably use autoit to send a control to the Arduino via USB COM port to do rapid fire, pretending to be a 2nd mouse via the Native USB. You'd probably still need to use a spare keyboard key or extra mouse button to trigger autoit to send the command to the Arduino rather than the left mouse button, but you can always try it and see what happens :)
I'd do this in stages, hook up a button to the due and get it doing mouseclicks as a 2nd mouse, then move on to serial comms and mapping to a key/button. Finally, I'd then implement the rapid fire on the due.
I would be surprised if the anticheat was unhappy with a script that didn't interact with any game binded keys, if it does then the only options left are to use a button on the arduino to do the rapidfire as a 2nd mouse, which is probably inconvenient, or, plug a mouse into the Due Native USB and forward all the movements to the PC as a serial mouse via the USB COM port. This may not be easy. You won't be able to plug the PC and mouse into the Native USB port and use something along the lines of the code you posted as this would require the port being a host and slave simultaneously and the PC would also see the mouse. The programming USB (COM) port can't be used as a generic USB device.

I may have a go at this myself at some point, there are times when 'hardware macros' do work better :D (the autoit/Due version, not the in-line method, too crazy for me :) )


I literally know nothing of what you are talking about, since I am so knew at this. Could you give me subjects I could research so I have a better understanding of this communication stuff, because of right now I barely have a clue what that means or how it applies to AutoHotkey. If you do end up trying it yourself do you mind giving me the code of how you did it?
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 08, 2017, 06:13 am
Also is the Due able to appear as  a HID like the Leonardo is? Like if I wanted to make it appear as a mouse?
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 08, 2017, 02:22 pm
What do you mean by sending commands? Serial?
Yes :)

This anti-cheat is insane, it literally scans through what you are running with your ram. Macros are a big think in competative Call of Duty, so I am just afraid that since AutoHotkey/AutoIt is such a popular method of making macros, that it will be picked up or picked up as a even a cheat.
You can compile the autoit code, so as long as it doesn't directly interact with the game, it shouldn't be picked up. A lot of mice and keyboards have macro options built-in, are they going after those as well?
The windows OS is pretty insecure which is why autoit works, you can hook into most of the system and do things, like pretend to be a mouse, up to a certain point, the system doesn't know if it's a real mouse, there's a number of layers to jump through between the real mouse and what the OS and/or games can see, a quick google:
"There is no way to detect if the mouse is a real one or a really well simulated one. The Windows HID/MacOS/Linux driver layer abstracts away the distinction between Mice, TrackPens, TrackBalls, draw-pads, touch screens... and of course script-mice.."

I would go for an autoit version until they break it, then redirect the control to the Due via serial

I am pretty new at this stuff which kind sucks and limits me on what I wanna do.
That will change :)

I literally know nothing of what you are talking about, since I am so knew at this. Could you give me subjects I could research so I have a better understanding of this communication stuff, because of right now I barely have a clue what that means or how it applies to AutoHotkey. If you do end up trying it yourself do you mind giving me the code of how you did it?
There's the autoit com port stuff:
https://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/
and obviously the arduino com port stuff:
https://www.arduino.cc/en/reference/serial

The Due just has to sit and listen to the serial port (the programming USB port looks like a serial port on the PC), autoit could send a single byte, 'N' for 'oN' F for 'oFf' and the Due reacts by autofiring as a mouse via the native USB port when it sees 'N', then switches the autofire off when it sees 'F'

@westfw 's idea(s) should all work too.

Another option is to modify a mouse to autofire directly.
https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=mouse%20autofire%20hack
I both love and hate this solution. If there was a spare button on the mouse, I'd wire that to do the autofire on the left using a 555.

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 08, 2017, 11:53 pm
Yes :)

You can compile the autoit code, so as long as it doesn't directly interact with the game, it shouldn't be picked up. A lot of mice and keyboards have macro options built-in, are they going after those as well?
The windows OS is pretty insecure which is why autoit works, you can hook into most of the system and do things, like pretend to be a mouse, up to a certain point, the system doesn't know if it's a real mouse, there's a number of layers to jump through between the real mouse and what the OS and/or games can see, a quick google:
"There is no way to detect if the mouse is a real one or a really well simulated one. The Windows HID/MacOS/Linux driver layer abstracts away the distinction between Mice, TrackPens, TrackBalls, draw-pads, touch screens... and of course script-mice.."

I would go for an autoit version until they break it, then redirect the control to the Due via serial
That will change :)

There's the autoit com port stuff:
https://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/
and obviously the arduino com port stuff:
https://www.arduino.cc/en/reference/serial

The Due just has to sit and listen to the serial port (the programming USB port looks like a serial port on the PC), autoit could send a single byte, 'N' for 'oN' F for 'oFf' and the Due reacts by autofiring as a mouse via the native USB port when it sees 'N', then switches the autofire off when it sees 'F'

@westfw 's idea(s) should all work too.

Another option is to modify a mouse to autofire directly.
https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=mouse%20autofire%20hack
I both love and hate this solution. If there was a spare button on the mouse, I'd wire that to do the autofire on the left using a 555.


Thanks for all the information!

Something that I should mention is that the anti-cheat is client side, meaning that they have this insane program that runs as administrator on your PC. It all sounds good except the AutoIt seems to be the only part that sounds kinda sketchy.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 09, 2017, 02:40 am
Yes :)

You can compile the autoit code, so as long as it doesn't directly interact with the game, it shouldn't be picked up. A lot of mice and keyboards have macro options built-in, are they going after those as well?
The windows OS is pretty insecure which is why autoit works, you can hook into most of the system and do things, like pretend to be a mouse, up to a certain point, the system doesn't know if it's a real mouse, there's a number of layers to jump through between the real mouse and what the OS and/or games can see, a quick google:
"There is no way to detect if the mouse is a real one or a really well simulated one. The Windows HID/MacOS/Linux driver layer abstracts away the distinction between Mice, TrackPens, TrackBalls, draw-pads, touch screens... and of course script-mice.."

I would go for an autoit version until they break it, then redirect the control to the Due via serial
That will change :)

There's the autoit com port stuff:
https://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/
and obviously the arduino com port stuff:
https://www.arduino.cc/en/reference/serial

The Due just has to sit and listen to the serial port (the programming USB port looks like a serial port on the PC), autoit could send a single byte, 'N' for 'oN' F for 'oFf' and the Due reacts by autofiring as a mouse via the native USB port when it sees 'N', then switches the autofire off when it sees 'F'

@westfw 's idea(s) should all work too.

Another option is to modify a mouse to autofire directly.
https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=mouse%20autofire%20hack
I both love and hate this solution. If there was a spare button on the mouse, I'd wire that to do the autofire on the left using a 555.


Also it would be easier for me if it was done on AutoHotkey (if it's possible idk) because I have a fair bit of understand on how to use that.

Also would using a powered USB hub or if I buy the USB Host Sheild make it any easier to do it the other way?
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 09, 2017, 06:29 am

Thanks for all the information!

Something that I should mention is that the anti-cheat is client side, meaning that they have this insane program that runs as administrator on your PC. It all sounds good except the AutoIt seems to be the only part that sounds kinda sketchy.

I don't really want to mess up my mouse though that is the thing. I use different mouses too sometimes and they are both quite expensive. My aim for this project is:

Have the clicking be coming from External, I don't care how complicated or messy it is on the outside as long as it's external I don't care it's not for looks.

Having the ability to use code so I can code it the way I want and add things like random delays etc.

Be able to use with any of my gaming mice. (not one modded bad mouse)

The external clicks to appear like they are coming from a real HID device (mouse)



Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 09, 2017, 09:52 am
A hub isn't going to help, but a host shield might. I took a quick look at one of the host shields and it appears it would need modifying to work, it uses 5v I/O, it's actually level shifted from 3v3, so it's just a case of removing it.
Another option would be a foot operated switch connected to the Due (possibly more convenient than trying to fit one somewhere easy to reach by hand). This has the advantage that you don't need some other button to disable autofire.
Note that with the Due-inline method, any special features of your mice will likely be unavailable. There may also be side-effects such as finding a bug in the code in the middle of a shootout :D

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 09, 2017, 11:52 pm
I am not an expert in any means like this like you are but I did some research and I am wondering if this solution would work.

https://www.amazon.com/IOGEAR-Cable-Switch-Audio-GCS72U/dp/B002K0TU2C

My thought process with this is I found a slue of these things that have the ability to use one mouse/keyboard or even monitor for two PCs. I was wondering if I could use this instead for the inline method because as I understood what you said is the reason the inline method would be hard to do is because you would have to transfer the movements, mouse clicks etc through the board and you would have to do it like code (kinda like coding like a all new mouse or making a air mouse out of these things). So I was wondering if the mouse was split where one could go into my computer like normal and other other could go into the arduino board reading "getBUttonStatus" and stuff would that work?
Or is there another reason why this won't work?
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 10, 2017, 10:06 am
A hub isn't going to help, but a host shield might. I took a quick look at one of the host shields and it appears it would need modifying to work, it uses 5v I/O, it's actually level shifted from 3v3, so it's just a case of removing it.
Another option would be a foot operated switch connected to the Due (possibly more convenient than trying to fit one somewhere easy to reach by hand). This has the advantage that you don't need some other button to disable autofire.
Note that with the Due-inline method, any special features of your mice will likely be unavailable. There may also be side-effects such as finding a bug in the code in the middle of a shootout :D


Sorry, meant to quote that ^^^.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 10, 2017, 03:15 pm
KVMs switch control between the 2 computers so the mouse control only appears on one of the USB cables at a time. There isn't really an off the shelf solution for that as nobody wants to supply exactly the same mouse controls to 2 pcs (and if you did, you'd use a software solution to do it via the network so that you can account for different screen resolutions and mouse acceleration settings in the OS).
You'd also have the same USB conundrum to solve, you'd need to be a host to the mouse and a client (device) to the PC.
I don't think forwarding the mouse controls using the inline method will be too hard, there's just the issue of what method you use to achieve it. For simplicity with no extra hardware, I'd go for serial mouse emulation via the programming port and attach the real mouse to the native port.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 10, 2017, 08:03 pm
KVMs switch control between the 2 computers so the mouse control only appears on one of the USB cables at a time. There isn't really an off the shelf solution for that as nobody wants to supply exactly the same mouse controls to 2 pcs (and if you did, you'd use a software solution to do it via the network so that you can account for different screen resolutions and mouse acceleration settings in the OS).
You'd also have the same USB conundrum to solve, you'd need to be a host to the mouse and a client (device) to the PC.
I don't think forwarding the mouse controls using the inline method will be too hard, there's just the issue of what method you use to achieve it. For simplicity with no extra hardware, I'd go for serial mouse emulation via the programming port and attach the real mouse to the native port.
Okay even though I probably wouldn't do the inline method how do I do that?
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 11, 2017, 09:40 am
Okay even though I probably wouldn't do the inline method how do I do that?
1) Connect the USB mouse to the native USB port on the Due using an on-the-go adaptor (I admit, I've never used one or done this so I am making the assumption that this is the correct method)
2) Write Arduino code to read the mouse buttons and movement
3) connect the programming port to the PC and install serial port mouse drivers
4) Write Arduino code to send serial port mouse buttons and movement obtained from the code in (2)
5) write yet more code which sits between (2) and (4) which alters the state of the mouse button as appropriate
You may have to google around for code you like the look of for the serial mouse emulation.
I would do (1) and (2) then output the mouse controls to the serial monitor in the Arduino IDE, then continue with (3) and (4) when I was happy that the mouse was being read correctly. I would then only do (5) when the  Arduino was successfully passing all the mouse control to the PC.

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 11, 2017, 10:21 pm
1) Connect the USB mouse to the native USB port on the Due using an on-the-go adaptor (I admit, I've never used one or done this so I am making the assumption that this is the correct method)
2) Write Arduino code to read the mouse buttons and movement
3) connect the programming port to the PC and install serial port mouse drivers
4) Write Arduino code to send serial port mouse buttons and movement obtained from the code in (2)
5) write yet more code which sits between (2) and (4) which alters the state of the mouse button as appropriate
You may have to google around for code you like the look of for the serial mouse emulation.
I would do (1) and (2) then output the mouse controls to the serial monitor in the Arduino IDE, then continue with (3) and (4) when I was happy that the mouse was being read correctly. I would then only do (5) when the  Arduino was successfully passing all the mouse control to the PC.


I think this method would be good to but I really don't understand how I would code it. I am in college right now and I don't have the time to make something like this so the only way I could use this solution is to pay someone to do that. I understand the serial communication method on the side of the Arduino (as in reading serial from the computer) but I really don't understand how to write it with something like AutoHotkey. Like I said my best option would be to pay for someone to write this code for me because I don't have much time available to research let alone code because of my exams that are coming up and they are more of a priority.

You are way smarter than me on this so when I go to research I usually don't end up with many search results because I don't think I am looking up the right thing.

For the KVM switch thing I found that solution out of luck and didn't really understand why it would work or why it wouldn't work. I thought basically what it does it is it switches back and forth the connection to two PC's which allows two mice and two keyboards to be connected simultaneously. Which is why I thought that it could be a possible solution to my problem because with my theory if I did that then I wouldn't have to code any crazy mice movement translations. 

Also what is westftw's ideas? I don't understand them completely but they sound good and I ignored them just because of the fact I don't understand what he is saying.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 12, 2017, 09:37 am
There is no autoit/autohotkey code to write on the PC for that solution, it uses serial mouse drivers. For debugging you just use the Arduino serial monitor to see what's going on so again, no PC code to write there either.

The other reason a KVM might not work is the same problem of mapping the left mouse button to autofire, how does windows know which left mouse button is correct? It may just hold the mouse button down all the time and not autofire/repeat. But that's irrelevent, KVMs don't split the control between 2 PCs, could you imagine trying to look at the output from 2 PCs on 1 monitor that's switching between the 2 at a fast rate? Not that this would even work because the video output from the 2 PCs isn't synced, so the monitor will take some time to lock on to the signal when it switches.
From the product description:
"Users can switch between computers using a manual pushbutton switch located on a wired remote that can be placed on your desk for convenience."

westftw's ideas both solve the usbhost/client problem by making either the input or the output a ps2 mouse connection. this only works if you have a ps2 mouse or a ps2 connection on the PC. You also need an appropriate ps2 connector, either to plug the mouse into or to plug into the PC.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 13, 2017, 04:55 am
I think that I finally understand your previous post, but just correct me if I am wrong.

So basically what I was thinking of coding it is basically using many if statements and put them in the void loop ()?

I am not going to use the exact code for lack of time.

If (get.Button(left)) //will have to make this one more complex if I was thinking of making the clicker run while I had this pressed, but for now I am just wondering the code for the mouse emulation.
{
Mouse.press(left))
}

while (get.Button(right)) //emulate the right click and other mouse buttons to the computer with this code???
{
Mouse.press(right)
}
if (!get.Button(right))
{
Mouse.release(right)
}

This is where I get confused, couldn't I just used getXchange() and getYChange() and just make those values be set as variables where a few lines later just does mouse.move()?

I think that I am missing a big portion of this but with your good explaining I am starting to understand it more.
If I were to pay someone to make this code for me what is a reliable place to go and what would something like this cost to make?


Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 13, 2017, 12:57 pm
There are some issues. Firstly, I went for a google and came back without finding any serial mouse emulation. I did find PS2 emulation:
http://playground.arduino.cc/ComponentLib/Ps2mouse (http://playground.arduino.cc/ComponentLib/Ps2mouse)
but this does require wiring up a PS2 connection with the Arduino, I'd find an old PS2 mouse and "borrow" the cable. The emulation code is at the bottom of that page.

The while loop you have there will block mouse movement while the right button is pressed.

The mouse.press() commands are for emulating mouse movements via the native USB port, but this is where your USB mouse will be connected, so there will be a different command depending on the emulation solution (serial or PS2). Same for mouse.move().
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 13, 2017, 02:00 pm
There are some issues. Firstly, I went for a google and came back without finding any serial mouse emulation. I did find PS2 emulation:
http://playground.arduino.cc/ComponentLib/Ps2mouse (http://playground.arduino.cc/ComponentLib/Ps2mouse)
but this does require wiring up a PS2 connection with the Arduino, I'd find an old PS2 mouse and "borrow" the cable. The emulation code is at the bottom of that page.

The while loop you have there will block mouse movement while the right button is pressed.

The mouse.press() commands are for emulating mouse movements via the native USB port, but this is where your USB mouse will be connected, so there will be a different command depending on the emulation solution (serial or PS2). Same for mouse.move().
Okay gotcha and what do you mean by "borrowing" the cable, if I wanted to use a gaming mouse which is USB how would I do that? Is it the same?

I found something online that takes a USB connection and turns it into ps/2 like a converter, is that somewhat what you are talking about?
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 13, 2017, 06:34 pm
Okay gotcha and what do you mean by "borrowing" the cable, if I wanted to use a gaming mouse which is USB how would I do that? Is it the same?
You plug the USB mouse into the Native port on the Arduino Due, then find an old PS2 mouse or keyboard and cut the cable off it so you can connect the cut end to the Arduino and the connector end into the PC, so that the Arduino can pretend to be a PS2 mouse, passing the the USB mouse controls to the PC.

I found something online that takes a USB connection and turns it into ps/2 like a converter, is that somewhat what you are talking about?
I wasn't thinking of using those, but you might need one if your PC doesn't have a PS2 port
If it looks like this then yes, it should work:
(https://farm8.staticflickr.com/7559/15210482833_59a103eda8_o.jpg)

But not if it looks like this:
(https://upload.wikimedia.org/wikipedia/commons/5/57/USB_to_PS2_mouse_adapter.jpg)

Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 14, 2017, 06:36 am
Alright I think I am close here for coming up with a solution. I have a few questions:

So now that I have a script that will basically emulate a USB mouse, where and how do I add the code where it autoclicks? Will the two codes interfere at all? Will this downgrade the performace of my mouse to make it harder to play? Like my mouse is set to 1000hz by defualt but I am fine playing on 500hz if I have too but I don't want to play on anything that is delayed noticably.

How do I take attach the PS/2 cable into the Arduino?

Thanks!
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 14, 2017, 11:19 pm
Take a look at the PS2 code, it should indicate which pins to connect to.

Where and how the autoclick will fit depends on the code you have.
You will need to record the time the button is pressed, something like:
Code: [Select]
//define these somewhere sensible
bool LeftState = false;// state of the real mouse button
bool LeftOutput = false;// to store the state of the fake mouse left button
unsigned long ClickTime;// to store the time of a click/release
#define Rate 50 // press and release time, in milliseconds [rep rate is 1000/(2*Rate) ]

// this goes in the loop
  bool newLeftState = mouse.getButton(LEFT_BUTTON);
  if (newLeftState != LeftState) {
    LeftState = newLeftState;
    if (LeftState)  {
      ClickTime = millis();
      Mouse.press(MOUSE_LEFT);
      LeftOutput = true;
    }
  }

Then when the button is pressed, alternate the button state at a fixed rate:
Code: [Select]
// this goes in the loop
if (LeftState)  {
    if (millis() - ClickTime >= Rate) {
      ClickTime = millis(); // new start time for timing the next change in left mouse state
      LeftOutput != LeftOutput; //toggle the state
      if (LeftOutput) {
        Mouse.press(MOUSE_LEFT);
      }
      else  {
        Mouse.release(MOUSE_LEFT);
      }
    }
  }

obviously Mouse.press() and Mouse.release() will change depending on the PS2 code, which I've not had time to look at.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 15, 2017, 06:20 am
Take a look at the PS2 code, it should indicate which pins to connect to.

Where and how the autoclick will fit depends on the code you have.
You will need to record the time the button is pressed, something like:
Code: [Select]
//define these somewhere sensible
bool LeftState = false;// state of the real mouse button
bool LeftOutput = false;// to store the state of the fake mouse left button
unsigned long ClickTime;// to store the time of a click/release
#define Rate 50 // press and release time, in milliseconds [rep rate is 1000/(2*Rate) ]

// this goes in the loop
  bool newLeftState = mouse.getButton(LEFT_BUTTON);
  if (newLeftState != LeftState) {
    LeftState = newLeftState;
    if (LeftState)  {
      ClickTime = millis();
      Mouse.press(MOUSE_LEFT);
      LeftOutput = true;
    }
  }

Then when the button is pressed, alternate the button state at a fixed rate:
Code: [Select]
// this goes in the loop
if (LeftState)  {
    if (millis() - ClickTime >= Rate) {
      ClickTime = millis(); // new start time for timing the next change in left mouse state
      LeftOutput != LeftOutput; //toggle the state
      if (LeftOutput) {
        Mouse.press(MOUSE_LEFT);
      }
      else  {
        Mouse.release(MOUSE_LEFT);
      }
    }
  }

obviously Mouse.press() and Mouse.release() will change depending on the PS2 code, which I've not had time to look at.

Okay thanks I think I gotcha.

I guess all that is left to know is how to make that autoclicker and my usb work with this code an I am all good. Instead of a fixed rate could I do it at a random rate btw? Or would the code have to change a lot because of this?
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 15, 2017, 03:17 pm
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.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 16, 2017, 12:31 am
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?
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 16, 2017, 12:43 am
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?
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 16, 2017, 09:44 am
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.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 17, 2017, 05:38 am
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
Title: Re: Help with mouse input and output?
Post by: MorganS on Jan 17, 2017, 09:02 am
Assistance withdrawn.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 17, 2017, 04:37 pm
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.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 17, 2017, 04:53 pm
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.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 17, 2017, 05:31 pm
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?
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 17, 2017, 06:08 pm

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.
Title: Re: Help with mouse input and output?
Post by: MorganS on Jan 18, 2017, 06:30 am
Assistance withdrawn.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 18, 2017, 09:53 am
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)
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 18, 2017, 10:00 am
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
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 18, 2017, 10:09 am
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).
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 18, 2017, 07:51 pm
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?

Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 18, 2017, 08:49 pm
The pedal doesn't really get power as such, it's just a switch. The instructable says pin 7 was used for the switch, the other end of the switch connects to 0v (gnd). The pin is configured with an internal pullup resistance, when the switch is open, it sees a '1', when it is closed the pin is connected to 0v, so it sees a '0'.

Another option is a switch mounted on a glove such that you can easily activate it with your thumb, the options are endless, it comes down to whatever solution you feel comfortable using. You might find using your heel is easier to use on a foot switch than the font of the foot, the trick is to play around until you find something that works, even if it seems odd. If you can wiggle your ears you could attach a sensor to them :D
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 19, 2017, 05:38 am
Okay but the foot petals seem like a good idea, so the foot petal isn't producing any power?


If I have this right: The Arduino Due (One of the pins) -------> Jumper Wire -------> Foot Pedal (If it is pressed it closes or opens the circuit.. idk but doesnt rlly matter) -----> Goes back to GRD. Send data to Arduio which would be connected to the computer via it's Programming Ports to send the mouseclick script?

Also I literally have none of the supplies:

What I have:   +The Due Board

                    + micro usb cable meant for phones but what I use for the Arduino

What I (think I need): + Foot Pedal Switch

                               + Jumper Cables: Which ones? Here's what I picked Tell me if its good
https://www.amazon.ca/Aukru-Female-Dupont-Arduino-Raspberry/dp/B019SX72CI/ref=sr_1_9?ie=UTF8&qid=1484799998&sr=8-9&keywords=arduino%2Bjumper%2Bwires&th=1

For the foot switch what I am looking for is something that is going to last, isn't very expensive and preferable has close shipping to me not really long shipping times. (I live in Canada and would like to order something in Canada maybe off Amazon.ca). Anyways since I have literally 0 knowledge on this type of stuff I don't really know what to order for this? Could you give me some help? I understand the whole concept of it I just don't know how the guy making that instructable knew that the inside would be basically empty and stuff. Thanks!
Title: Re: Help with mouse input and output?
Post by: MorganS on Jan 19, 2017, 06:29 am
Assistance withdrawn.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 19, 2017, 09:40 am
Okay but the foot petals seem like a good idea, so the foot petal isn't producing any power?
Yup. I rather like MorganS' reply.

If I have this right: The Arduino Due (One of the pins) -------> Jumper Wire -------> Foot Pedal (If it is pressed it closes or opens the circuit.. idk but doesnt rlly matter) -----> Goes back to GRD. Send data to Arduio which would be connected to the computer via it's Programming Ports to send the mouseclick script?
The Due has 2 USB ports, although you may program using either, to act as a USB mouse, you must use the 'Native' port, not the one labelled 'Programming'.

What I (think I need): + Foot Pedal Switch

                               + Jumper Cables: Which ones? Here's what I picked Tell me if its good
https://www.amazon.ca/Aukru-Female-Dupont-Arduino-Raspberry/dp/B019SX72CI/ref=sr_1_9?ie=UTF8&qid=1484799998&sr=8-9&keywords=arduino%2Bjumper%2Bwires&th=1
If the foot pedal has pins inside that will accept those jumpers then it will be easy, but you may not know until you get it unless there are decent pics or datasheet for it. Do you have a soldering iron, or a friend who does? I'd buy some twin core cable and some 0.1" pitch headers and make a lead that fits my own requirements. Those jumpers are short, it looks like you could daisy-chain them together but that's pretty ugly and a bit expensive way to make a cable (and more connections = less reliability).


For the foot switch what I am looking for is something that is going to last, isn't very expensive and preferable has close shipping to me not really long shipping times. (I live in Canada and would like to order something in Canada maybe off Amazon.ca). Anyways since I have literally 0 knowledge on this type of stuff I don't really know what to order for this? Could you give me some help? I understand the whole concept of it I just don't know how the guy making that instructable knew that the inside would be basically empty and stuff. Thanks!
This is a tougher question. I'd get the cheapest I can find and play with it for a bit, to make sure I didn't cripple myself in battle. long term I might try to find one with adjustable spring tension, or potentially make my own (I smell another reason to get a 3D printer...)

As for knowing the pedal would be mostly empty, you have to guess what it takes to make one, everything comes down to cost, so you guess that the inside has a spring and a switch, they don't need to be big, so there's probably a lot of empty space. Experience plays a part here.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 24, 2017, 03:05 pm
Yup. I rather like MorganS' reply.

The Due has 2 USB ports, although you may program using either, to act as a USB mouse, you must use the 'Native' port, not the one labelled 'Programming'.
If the foot pedal has pins inside that will accept those jumpers then it will be easy, but you may not know until you get it unless there are decent pics or datasheet for it. Do you have a soldering iron, or a friend who does? I'd buy some twin core cable and some 0.1" pitch headers and make a lead that fits my own requirements. Those jumpers are short, it looks like you could daisy-chain them together but that's pretty ugly and a bit expensive way to make a cable (and more connections = less reliability).

This is a tougher question. I'd get the cheapest I can find and play with it for a bit, to make sure I didn't cripple myself in battle. long term I might try to find one with adjustable spring tension, or potentially make my own (I smell another reason to get a 3D printer...)

As for knowing the pedal would be mostly empty, you have to guess what it takes to make one, everything comes down to cost, so you guess that the inside has a spring and a switch, they don't need to be big, so there's probably a lot of empty space. Experience plays a part here.
Although untested, I think I found some code that will work in terms of having the mouse do rapid fire from
looking at a similar post on reddit.

In my theory, this looks like it would work but then again you are the experienced one here so I was wondering if you could tell me if it works or not? If not, what is it used for?

https://github.com/pontech/MouseHID


Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 24, 2017, 04:08 pm
There's no real documentation, but a quick look at the code suggests it emulates a mouse using 9 input pins. I don't think it does autofire (I didn't dive too deep into the code). I don't even know for sure this will work on the Due, it will certainly require changes, the pin definitions are weird for a start :)
It was designed to run on this:
http://chipkit.net/wpcproduct/pontech-quick240/ (http://chipkit.net/wpcproduct/pontech-quick240/)
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 24, 2017, 05:48 pm
There's no real documentation, but a quick look at the code suggests it emulates a mouse using 9 input pins. I don't think it does autofire (I didn't dive too deep into the code). I don't even know for sure this will work on the Due, it will certainly require changes, the pin definitions are weird for a start :)
It was designed to run on this:
http://chipkit.net/wpcproduct/pontech-quick240/ (http://chipkit.net/wpcproduct/pontech-quick240/)

Okay thanks.

I made this code which I thought would work if I had a on the Go adaptor or a USB HOST SHIELD with my Due. In my logic it works, well I am at least pretty sure that at least the mouse button press and release works but idk about the move. If it doesn't work could you explain why because I don't understand what this class does otherwise.

// Require mouse control library
#include <MouseController.h>

// Initialize USB Controller
USBHost usb;

// Attach mouse controller to USB
MouseController mouse(usb);

// variables for mouse button states
boolean leftButton = false;
boolean middleButton = false;
boolean rightButton = false;
int MouseX;
int MouseY;
int MouseXD;
int MouseYD;

// This function intercepts mouse movements
void mouseMoved() {
 
  MouseX = mouse.getXChange();
 
  MouseY = mouse.getYChange();
Mouse.move(MouseX, MouseY, wheel);


}

// This function intercepts mouse movements while a button is pressed
void mouseDragged() {
 
   MouseXD = mouse.getXChange();
 
  MouseYD = mouse.getYChange();
Mouse.move(MouseXD, MouseYD, wheel);

}

// This function intercepts mouse button press
void mousePressed() {

  while (mouse.getButton(LEFT_BUTTON)){
    // autoclicker while loop
  }
  if (mouse.getButton(MIDDLE_BUTTON)){
    Mouse.press(MOUSE_MIDDLE)
    middleButton = true;
  }
  if (mouse.getButton(RIGHT_BUTTON)){
    Mouse.press(MOUSE_RIGHT)
    rightButton = true;
  }
}

// This function intercepts mouse button release
void mouseReleased() {
 
  if (!mouse.getButton(LEFT_BUTTON) && left==true) {
    Mouse.release(LEFT_BUTTON);
    leftButton = false;
  }
  if (!mouse.getButton(MIDDLE_BUTTON) && middle==true) {
   Mouse.release(MIDDLE_BUTTON);
    middleButton = false;
  }
  if (!mouse.getButton(RIGHT_BUTTON) && right==true) {
    Mouse.release(RIGHT_BUTTON);
    rightButton = false;
  }
 
}

void setup()
{
  Serial.begin(9600);
  Serial.println("Program started");
  delay(200);
}

void loop()
{
  // Process USB tasks
  usb.Task();
}
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 24, 2017, 07:18 pm
A host shield should work. An OTG adaptor would still require a USB shield (but wouldn't need to have host capability) because the Due doesn't have 2 true USB ports.
Calling them Mouse and mouse is very confusing...
There are a lot of coding errors so this simply won't compile as it is. This looks just like some code I spotted the other day which wouldn't compile, some of the errors are exactly the same...

"leftButton" isn't the same as "left"
What's LEFT_BUTTON, it certainly isn't listed here: https://www.arduino.cc/en/Reference/MousePress (https://www.arduino.cc/en/Reference/MousePress)

Putting in an autoclicker while loop will block other code from running, so mouse movements won't happen, in fact, it will lock you out forever. What you need to do is set/clear a variable in the pressed/released functions then deal with the clicking in the main loop (without using any delays or dodgy while loops), the code in post 28 might do that (I've not actually tested it).

I think you modified this:
https://www.arduino.cc/en/Tutorial/MouseController (https://www.arduino.cc/en/Tutorial/MouseController)
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 24, 2017, 08:36 pm
A host shield should work. An OTG adaptor would still require a USB shield (but wouldn't need to have host capability) because the Due doesn't have 2 true USB ports.
Calling them Mouse and mouse is very confusing...
There are a lot of coding errors so this simply won't compile as it is. This looks just like some code I spotted the other day which wouldn't compile, some of the errors are exactly the same...

"leftButton" isn't the same as "left"
What's LEFT_BUTTON, it certainly isn't listed here: https://www.arduino.cc/en/Reference/MousePress (https://www.arduino.cc/en/Reference/MousePress)

Putting in an autoclicker while loop will block other code from running, so mouse movements won't happen, in fact, it will lock you out forever. What you need to do is set/clear a variable in the pressed/released functions then deal with the clicking in the main loop (without using any delays or dodgy while loops), the code in post 28 might do that (I've not actually tested it).

I think you modified this:
https://www.arduino.cc/en/Tutorial/MouseController (https://www.arduino.cc/en/Tutorial/MouseController)
Yeah I did modify that code lol.

So basically if I were to fix those stupid errors that I did the code would work? With a USB port adapter thing.

I can't wrap my head around on why the code, even in the class where I got it from doesn't work (From what I understand you saying). I understand that using Delay() or a while dodgy while loop would block it though. Basically I created a pretty complex algorithm to generate the random commands in the code. I don't want to bore you but basically I made it have a possibility of 5 clicking variation speeds each time it cycles. (30% for 100ms delay total, 30% for 90 delay total, 14% for 70ms delay total, etc.) After selecting the delay total it chooses the delay for the click sleep (how long click is pressed) and the interval sleep (delay between clicks) (randomizes which if it chooses click sleep first or interval sleep). After this there is only one remaining (either click sleep or click interval)  and that would be the one it didn't choose orginally where it  would just set that too the sum - the other delay. This is the code required to bypass the anticheat, but it is basically just if statements that could be placed anywhere. I need to create a autoclicking system with this code that doesn't use any weird blocks but I can't quite figure it out.

Would something like this work with my mouse/code/due if I got it to work?
https://www.amazon.ca/Shield-Module-Android-Arduino-Duemilanove/dp/B01KL4IO98/ref=sr_1_2?ie=UTF8&qid=1485286769&sr=8-2&keywords=usb+host+shield
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 25, 2017, 06:55 am
A host shield should work. An OTG adaptor would still require a USB shield (but wouldn't need to have host capability) because the Due doesn't have 2 true USB ports.
Calling them Mouse and mouse is very confusing...
There are a lot of coding errors so this simply won't compile as it is. This looks just like some code I spotted the other day which wouldn't compile, some of the errors are exactly the same...

"leftButton" isn't the same as "left"
What's LEFT_BUTTON, it certainly isn't listed here: https://www.arduino.cc/en/Reference/MousePress (https://www.arduino.cc/en/Reference/MousePress)

Putting in an autoclicker while loop will block other code from running, so mouse movements won't happen, in fact, it will lock you out forever. What you need to do is set/clear a variable in the pressed/released functions then deal with the clicking in the main loop (without using any delays or dodgy while loops), the code in post 28 might do that (I've not actually tested it).

I think you modified this:
https://www.arduino.cc/en/Tutorial/MouseController (https://www.arduino.cc/en/Tutorial/MouseController)
I mean still overall I believe that Serial Commication would be easiest option. There are two problems with that though.

1) I don't understand how to make it.

2) I am afraid that the anti-cheat will scan it as a cheat if it is compiled, or even read the code and disallow it. (two things that the anti-cheat can easily do).

But there are things I like about it:

1) Only need a Due and the cord

There is a part of me wanting to do this but I know that I will get banned for it soon enough so there is also a part that doesn't want to do it. The E-Sports league I am in costs $8 a month and if you get banned I am pretty sure they IP ban.
Title: Re: Help with mouse input and output?
Post by: MorganS on Jan 25, 2017, 07:16 am
Well there's where you just stepped over the line. If you had more experience with this forum you would know that the long term contributors will completely stop helping if they think your project is illegal, immoral or dangerous.

You could have left this as a practical excercise in mouse clicking but you have now given enough information that we can be sure that you are cheating.

Please don't give up on Arduino. It's lots of fun. I'm sure you'll have a science project within the next year that you can use your experience to look like some kind of genius to the rest of your team. I am willing to help with any project except this one.
Title: Re: Help with mouse input and output?
Post by: weird_dave on Jan 25, 2017, 11:35 am
I knew he was wanting to 'cheat' from the initial post. The thing is, I recall being able to buy joysticks with an autofire feature.
I have seen T's and C's which state that using any software or hardware that may give the player an advantage is not allowed, but where do you draw the line? Faster graphics and CPU clearly give an advantage, as do 4K monitors. Decent sound also falls into this category. OK, so autofire on a mouse isn't exactly normal, but maybe it should be, just like the old joysticks.
Since it is possible to click quite fast manually, I don't think an autofire function gives much advantage (I have seen anticheat reduce the click rate down to human levels if you over-egg it, either it was the anticheat or it wasn't polling the mouse events fast enough :) ), it may however reduce the risk of RSI. It may also waste ammo and reduce your hit rate stats.
There are plenty of mice and keyboards which come with macro functionality, it is easy to use these to do a whole bunch of stuff very quickly, obviously giving the player an advantage. The now defunct StarWars Galaxies MMORPG even had a built-in macro system which allowed the players to give themselves advantages.
I suspect that after an initial placebo effect, the perceived advantage will disappear as there is now less control. The user still has to control all the movement and aiming, but no longer has fine control over the amount of ammo used. It would certainly be interesting to find out if this project did have a benefit, if only to then decide if it should be allowed, as it stands it is borderline because we don't have enough information.
Title: Re: Help with mouse input and output?
Post by: David1937 on Jan 25, 2017, 02:50 pm
Well there's where you just stepped over the line. If you had more experience with this forum you would know that the long term contributors will completely stop helping if they think your project is illegal, immoral or dangerous.

You could have left this as a practical excercise in mouse clicking but you have now given enough information that we can be sure that you are cheating.

Please don't give up on Arduino. It's lots of fun. I'm sure you'll have a science project within the next year that you can use your experience to look like some kind of genius to the rest of your team. I am willing to help with any project except this one.
I knew he was wanting to 'cheat' from the initial post. The thing is, I recall being able to buy joysticks with an autofire feature.
I have seen T's and C's which state that using any software or hardware that may give the player an advantage is not allowed, but where do you draw the line? Faster graphics and CPU clearly give an advantage, as do 4K monitors. Decent sound also falls into this category. OK, so autofire on a mouse isn't exactly normal, but maybe it should be, just like the old joysticks.
Since it is possible to click quite fast manually, I don't think an autofire function gives much advantage (I have seen anticheat reduce the click rate down to human levels if you over-egg it, either it was the anticheat or it wasn't polling the mouse events fast enough :) ), it may however reduce the risk of RSI. It may also waste ammo and reduce your hit rate stats.
There are plenty of mice and keyboards which come with macro functionality, it is easy to use these to do a whole bunch of stuff very quickly, obviously giving the player an advantage. The now defunct StarWars Galaxies MMORPG even had a built-in macro system which allowed the players to give themselves advantages.
I suspect that after an initial placebo effect, the perceived advantage will disappear as there is now less control. The user still has to control all the movement and aiming, but no longer has fine control over the amount of ammo used. It would certainly be interesting to find out if this project did have a benefit, if only to then decide if it should be allowed, as it stands it is borderline because we don't have enough information.
I don't really understand what is wrong here or even what I said was wrong. Nothing I am doing with this has a conflict with the rules. If you think I am trying to cheat than like @weird_dave said, Why would I make such a low clicking speed where in fact it will bring me to a disadvantage when you bring in things such as recoil and stuff.
The reason why I am even needing to do this in the first place is I used to be able to click this fast normal clicking 10 clicks per second. However from clicking this fast and so much over time I have developed a problem in my hand (well I have all the symptoms) called Carpal Tunnel which you are probably aware of. I have also gone through many gaming mice in the past that are supposed to last 50 million clicks but since there is so much clicking they break within a month.

I honestly don't see this as cheating as @weird_dave is right I can literally normal click like 10 clicks a second which is as fast as I would need and would have more control then even the best Arduino code. I just don't want the problem in my hand to get worse. If I had real intentions of cheating I would have made my random code click a lot faster than 10-11 clicks a second, because the game likely wouldn't ban if I had it at 20 cps or something.
Title: Re: Help with mouse input and output?
Post by: AkiraKurai on Jan 26, 2017, 11:33 am
I don't really understand what is wrong here or even what I said was wrong. Nothing I am doing with this has a conflict with the rules. If you think I am trying to cheat than like @weird_dave said, Why would I make such a low clicking speed where in fact it will bring me to a disadvantage when you bring in things such as recoil and stuff.
The reason why I am even needing to do this in the first place is I used to be able to click this fast normal clicking 10 clicks per second. However from clicking this fast and so much over time I have developed a problem in my hand (well I have all the symptoms) called Carpal Tunnel which you are probably aware of. I have also gone through many gaming mice in the past that are supposed to last 50 million clicks but since there is so much clicking they break within a month.

I honestly don't see this as cheating as @weird_dave is right I can literally normal click like 10 clicks a second which is as fast as I would need and would have more control then even the best Arduino code. I just don't want the problem in my hand to get worse. If I had real intentions of cheating I would have made my random code click a lot faster than 10-11 clicks a second, because the game likely wouldn't ban if I had it at 20 cps or something.
So? you are using an illegal form of modification for that game regardless of if you can achieve the same speed without the mod. This is similar to how one person will automate a system that is flawless and then focus all their attention on another issue at hand. Also, I'll give you the hard truth. The company of whatever that game does not care of you get carpal tunnel you must follow the rules as they have stated in their own EULA.