Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2016-02-19 02:15:40

ZafingSpace
Member
Joined: 2016-01-26
Posts: 5

[How do you know]: If someone double pressed right or left arrow keys?

I always wanted to find out how do you know to make your bot know it someone double pressed an arrow key.


    I tried doing like the basics and do something simple like this.

  The point of this code is double press right arrow key and a block will appear right next to them
   

   switch (e.KeyCode)
    {
        if case e.DoublePress.Right;
        {
             con.Send(bldatam, 0, 1-x, y, 12);
        } 
    }
    break;

   

  It did not work at all! https://wiki.everybodyedits.com/images/c/c0/069_LOL

  I don't know if this code is simply or anything, can you help?

Offline

#2 2016-02-19 02:21:02

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: [How do you know]: If someone double pressed right or left arrow keys?

Are you pressing the keys in the application or in the world?

Either way you're going to need timestamps - so you can chose the variation of how quickly a double press is.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

Wooted by:

#3 2016-02-19 15:38:47

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [How do you know]: If someone double pressed right or left arrow keys?

As said, you need to know the time between 2 times the same key have been consecutively pressed, check if that time is rather short and you know if it's a double tap.

Offline

#4 2016-02-19 17:27:58

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: [How do you know]: If someone double pressed right or left arrow keys?

Basically what these folks said
I have no idea how you came across that code... or how that had a chance of fitting in

bt gj nvrthlss

Offline

#5 2016-02-19 20:12:09

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: [How do you know]: If someone double pressed right or left arrow keys?

# m - UserID is moving around
    [0] <Integer> UserID
    [1] <Double> PlayerPosX
    [2] <Double> PlayerPosY
    [3] <Double> SpeedX
    [4] <Double> SpeedY
    [5] <Integer> ModifierX
    [6] <Integer> ModifierY
    [7] <Integer> Horizontal
    [8] <Integer> Vertical
    [9] <Boolean> SpaceDown
    [10] <Boolean> SpaceJustDown

If m[7] == 1, the right key is pressed, and if it is -1, the left key is pressed.

You essentially need to receive 4 messages with certain amounts of time between each, to detect a double-tap: player presses a key, lets go, presses it again, and lets go. The messages would look like:

m[7] == 1   --> Player presses right
- Short amount of time passes (e.g. < 1 sec)
m[7] == 0  --> Player lets go of right key
- Short amount of time
m[7] == 1 --> Player presses right again
- Short amount of time
m[7] == 0 --> Player lets go of right

After that, you would do whatever action is triggered by that key combo. To check the amount of time between key presses, you would check the amount of time that passes between received "m" packets, using a Stopwatch object - see http://www.dotnetperls.com/stopwatch.

However, I think you'd find that players would trigger that combo quite often without meaning to, while just bouncing around. It would be better to have a more obscure combo, like Up + Left + Up, that normal movement would be less likely to trigger. To detect an Up key press, you would need m[8] -> m[8] == 1 if player presses Down, and -1 if player presses Up.

^^ Up, Up, Down, Down, Left, Right, A, B, A, B, Start.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#6 2016-02-19 22:01:15

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: [How do you know]: If someone double pressed right or left arrow keys?

Tomahawk wrote:

# m - UserID is moving around
    [0] <Integer> UserID
    [1] <Double> PlayerPosX
    [2] <Double> PlayerPosY
    [3] <Double> SpeedX
    [4] <Double> SpeedY
    [5] <Integer> ModifierX
    [6] <Integer> ModifierY
    [7] <Integer> Horizontal
    [8] <Integer> Vertical
    [9] <Boolean> SpaceDown
    [10] <Boolean> SpaceJustDown

If m[7] == 1, the right key is pressed, and if it is -1, the left key is pressed.

You essentially need to receive 4 messages with certain amounts of time between each, to detect a double-tap: player presses a key, lets go, presses it again, and lets go. The messages would look like:

m[7] == 1   --> Player presses right
- Short amount of time passes (e.g. < 1 sec)
m[7] == 0  --> Player lets go of right key
- Short amount of time
m[7] == 1 --> Player presses right again
- Short amount of time
m[7] == 0 --> Player lets go of right

After that, you would do whatever action is triggered by that key combo. To check the amount of time between key presses, you would check the amount of time that passes between received "m" packets, using a Stopwatch object - see http://www.dotnetperls.com/stopwatch.

However, I think you'd find that players would trigger that combo quite often without meaning to, while just bouncing around. It would be better to have a more obscure combo, like Up + Left + Up, that normal movement would be less likely to trigger. To detect an Up key press, you would need m[8] -> m[8] == 1 if player presses Down, and -1 if player presses Up.

^^ Up, Up, Down, Down, Left, Right, A, B, A, B, Start.

Add a timestamp to the player class so you don't end up with a new thread every time someone moves.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

#7 2016-02-19 22:45:59

BuzzerBee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,570

Re: [How do you know]: If someone double pressed right or left arrow keys?

Tomahawk wrote:

After that, you would do whatever action is triggered by that key combo. To check the amount of time between key presses, you would check the amount of time that passes between received "m" packets, using a Stopwatch object - see http://www.dotnetperls.com/stopwatch.

I would highly recommend not using a Stopwatch for non-diagnostic purposes. Stopwatches are great and accurate for seeing how long a code segment takes to execute, but not so efficient to use in finished programs.

I would recommend using a TimeSpan or a Timer to check the time between presses.

Good luck!


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#8 2016-02-20 03:48:59

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: [How do you know]: If someone double pressed right or left arrow keys?

BuzzerBee wrote:
Tomahawk wrote:

After that, you would do whatever action is triggered by that key combo. To check the amount of time between key presses, you would check the amount of time that passes between received "m" packets, using a Stopwatch object - see http://www.dotnetperls.com/stopwatch.

I would highly recommend not using a Stopwatch for non-diagnostic purposes. Stopwatches are great and accurate for seeing how long a code segment takes to execute, but not so efficient to use in finished programs.

I would recommend using a TimeSpan or a Timer to check the time between presses.

Good luck!

cite ur src plz

Offline

#9 2016-02-20 20:55:38, last edited by Koya (2016-02-20 21:10:16)

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: [How do you know]: If someone double pressed right or left arrow keys?

ZafingSpace wrote:
switch (e.KeyCode)
    {
        if case e.DoublePress.Right;
        {
             con.Send(bldatam, 0, 1-x, y, 12);
        } 
    }
    break;

I just realised what you wrote, switch statements are for a list of answers not a list of if statements, you don't say `if case` - you say `case var:` inside `switch`

switch(VAR) {
    case var1:
        //Do something
    break;
    case var2:
    case var3:
        //Do something if var2 or var3 match VAR
    break;
    default:
        //If the result doesn't match anything else
    case;
}

Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

Koya1455998138584240

Board footer

Powered by FluxBB

[ Started around 1714006701.7191 - Generated in 0.079 seconds, 12 queries executed - Memory usage: 1.52 MiB (Peak: 1.69 MiB) ]