Postby njp21434 » Fri 16 Dec, 2011 1:39 pm

I'm new to glovepie and i barely know how to use it

When i type in

Keyboard.A = (Keyboard.X && Keyboard.Z)

and run it when i press Z and X i want it to show A by itself but I also want Z or X to show when i press it by itself

Please help!!!!
Posts: 3
Joined: Thu 08 Dec, 2011 3:59 pm

Re: HELP!!

Postby CarlKenner » Mon 02 Jan, 2012 8:35 pm

Try it this way (probably not what you want):

Code: Select all
Keyboard.A = Keyboard.X && swallow(Keyboard.Z)
var.dummy = Keyboard.Z && swallow(Keyboard.X)

Notice how the keys are not swallowed as part of an AND expression unless the first part of the expression is true.
It has a slight bug though, if you hold down x, then hold down z then release x, then release x, then whenever you press Z you will get an A, until you press x again. And vice-versa. I'm not sure how to fix that.

Also, that script assumes you want the first key you press to be recognised by the game but then block out the second one while the first is still being held down. But that might not be what you want.

If you want X+Z at the same time to never trigger either X or Z, then it's harder. Because Keyboards don't understand "at the same time". Non-usb keyboards always trigger one key first, then the other. To detect both at the same time, we need a delay before the first key is recognised in case a second key follows it. We also need to wait when one key is released before we allow the other one to be recognised again, because you can't release both at exactly the same time. That adds some latency to pressing X or Z by themselves.

Code: Select all
var.X = swallow(RealKeyboard.X)
var.Z = swallow(RealKeyboard.Z)

FakeKeyboard.X = (helddown(var.X,100ms) || (released(var.X) && keepdown(pressed(var.X),100ms)))
... && (not var.Z) && (not KeepDown(Released(var.Z),100ms))

FakeKeyboard.Z = (helddown(var.Z,100ms) || (released(var.Z) && keepdown(pressed(var.Z),100ms)))
... && (not var.X) && (not KeepDown(Released(var.X),100ms))

Keyboard.A = var.X && var.Z

This looks very complicated, so I'll spell it out. First we swallow the X and Z keys so the game doesn't see them, and we assign them to variables. When to trigger the A key is simple, whenever both X and Z are true. But when to trigger the X key is more complicated. We don't want to trigger X right away when they press X, because it might be the start of an X+Z combination. We want to wait 100ms to give them time to press the Z key if they are going to. That's what helddown(var.X,100ms) means, it's true whenever the X key has been held down for at least 100ms. But what if they release the X key less than 100ms after they pressed it (that's what (released(var.X) && keepdown(pressed(var.X),100ms)) means), but didn't press Z during that time? We also want the X key to be triggered (for an instant) in that case. Of course we also need to make sure Z isn't down (&& (not var.Z)). But what happens if they release Z an instant before they release X (you can't really release them both at exactly the same time)? We don't want X to be triggered again as soon as Z is released, we want to wait to give them time to release X too. That's what not KeepDown(Released(var.Z),100ms) means, they have to not have released Z within the last 100ms.

There's a minor bug with this and the key repeat when you hold down x or z (but not when you hold down both). X and Z repeat slower than normal. I don't know what causes that.
Posts: 382
Joined: Sun 03 Jan, 2010 6:09 am

Return to Keyboard

Who is online

Users browsing this forum: No registered users and 1 guest