Konami Code (XInput / Dinput) Topic is solved

Ask gaming related questions
User avatar
elModo7
Posts: 35
Joined: 01 Sep 2017, 02:38

Konami Code (XInput / Dinput)

23 Jan 2018, 16:02

EDIT: XInput Done, now on to DInput method

This is driving me mad, can't manage to obtain a Konami Code detection using Joy inputs or XInput.
I mean, I can detect simultaneous button presses on both XInput and DInput, but when it comes to a sequence of buttons like the konami code one (https://i.amz.mshcdn.com/2BrPLT7CBA4q4AELMRDzXkxbAlM=/950x534/filters:quality(90)/2013%2F08%2F30%2F06%2FKonami.056d1.jpg) I really don't know how to make it. Maybe store inputs and then compare somehow?
:beer:
User avatar
evilC
Posts: 4083
Joined: 27 Feb 2014, 12:30

Re: Konami Code (XInput / Dinput)

24 Jan 2018, 08:14

This is quite technically tricky.
I am assuming that Up/Down/Left/Right are DPad (POV Hat) directions.
In AHK, these are read as an ANGLE (POV centered is -1, up is 0, Right is 9000, Down is 18000, etc...)

Also, you need to make sure that any button/direction could potentially "break" the sequence - so if the next thing in the sequence is UP, and we see A get pressed, then we need to break the sequence.

Here is some code which seems to work.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Here is a video of me testing it. I use vJoy as the INPUT, so I can use the "Demo Feeder" app to control the Dpad and buttons using mouse clicks, so you can see what I am doing in the recording.

Image
User avatar
evilC
Posts: 4083
Joined: 27 Feb 2014, 12:30

Re: Konami Code (XInput / Dinput)

24 Jan 2018, 09:24

Actually, this is quite a fun problem to try and solve in a generic, easily configurable manner.
As is usual with me, I did it with the power of Classes:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



In theory, this code should let you define any sequence of keyboard, mouse, joystick buttons POVs or Axes!
However with Axes, I doubt it would work properly, as you would have to match every single point the axis passes through, but I included it for completeness, or for devices that eg have digital axes.
User avatar
evilC
Posts: 4083
Joined: 27 Feb 2014, 12:30

Re: Konami Code (XInput / Dinput)

24 Jan 2018, 09:56

Also bear in mind that as I have used classes, you can run MULTIPLE SequenceWatchers at the same time.

For example, use this configuration to watch for Street Fighter fireball / dragon punch (Left and Right variants) plus the Konami Sequence.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
evilC
Posts: 4083
Joined: 27 Feb 2014, 12:30

Re: Konami Code (XInput / Dinput)

24 Jan 2018, 11:15

Whee! this is a fun problem to work on :)

Here is a version that lets you specify timing constraints for each key in the sequence.
Min = Minimum amount of time that has passed since the last key in the sequence
Max = Maximum amount of time that has passed since the last key in the sequence

You can optionally specify a DEFAULT min and max when you create the watcher:
dpr := new SeqWatcher(Func("DragonPunchRight"), 0, 100) Means "All keys in this sequence have no default Min value and a default Max value of 100ms

Then, when you add a key to the sequence, you can override the defaults:
dpr.AddSeq("a", 100, 300) Means "This key in the Sequence has a Min of 100ms and a Max of 300ms"
You can use -1 to mean "Use Default": dpr.AddSeq("a", -1, 300) Means "Use the Default Min and a Max of 300ms"
Bear in mind using 0 will override the default with 0: dpr.AddSeq("a", 0, 300) Means "Use Min of 0 and Max of 300, Regardless of what defaults are"

So, for example, to define a "Dragon Punch" sequence, where right/center/down/downright/right must occur within 100ms of each other (No Min) and the final press of A must occur between 100-300ms after the Right (ie you must wait a bit before pressing A, but not too long), you would use:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Here is the new library:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

MaxAstro
Posts: 537
Joined: 05 Oct 2016, 13:00

Re: Konami Code (XInput / Dinput)

24 Jan 2018, 15:25

Wow, I'm glad I happened to watch this thread out of curiosity. This is actually really useful to something I am currently working on.
User avatar
elModo7
Posts: 35
Joined: 01 Sep 2017, 02:38

Re: Konami Code (XInput / Dinput)  Topic is solved

09 Feb 2018, 04:37

This is what I ended up doing for the XInput version:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Basically the easy way as I'm a noob doing this things.
:beer:

Return to “Gaming”

Who is online

Users browsing this forum: Treb and 7 guests