ID:133512
 
I know that you can use macros to allow BYOND to record keypresses, but I wish there was procs that would:

A) Check if said key is pressed(Return 1 if pressed, 0 if not)
B) Run a proc when said key is released (IE: key_released("P"))

Is there any way to do these in BYOND currently, and if not, I'd like to suggest them. Small things like these are staples in most coding languages, but BYOND is lacking a few of them as far as I know.
You can do that in the skin.
This message applies to 4.0 macro through the interface (DMF):

Set up a verb (or two, hidden): One called when a key is pressed down (set up the macro so repeat is unchecked) and the other is called when the key is released (there's a check option for that as well):

Ex:
Macro for 'A' (no repeat, no up) --> KeyDown A
'A' when released (no repeat, up) --> KeyUp A

mob
var/tmp/list/keys[0] // initializes a list with 0 entries
verb
KeyDown(T as text)
set hidden = 1
keys[T] = 1 // Sets whatever key is down to 1 (ex: keys["A"] = 1
KeyUp(T as text)
set hidden = 1
keys[T] = 0
In response to Andre-g1
How? I don't mess around with skins very much(And know quite a few people who don't as well), so even then it'd be a lot easier if there was some procedures to use instead..
Mechana2412 wrote:
A) Check if said key is pressed(Return 1 if pressed, 0 if not)

That isn't really the good type of implementation. Sure, it's good to basically have, but it's not good to use regularly, eg
mob/Login() KeyLoop()
mob/proc/KeyLoop()
for()
if(KeyPressed(10)) //key id
//do stuff
sleep(1)

//the above is
// BAD


So it's not necessary, just nice to have. But remember it's inefficient generally.

B) Run a proc when said key is released (IE: key_released("P"))

Put a built-in macro that runs a verb when that happens (use the interface editor, not DM Script, which is outdated).
In response to GhostAnime
(Pardon for double post, didn't see Ghost's response)

I can see how the code works, but you're losing me with the macro settings..
In response to Kaioken
That isn't the implementation I was thinking of. I was thinking of using it when another key is pressed to check if another key is pressed when that happens, IE if E is pressed while you press A.
In response to Mechana2412
Try setting up a macro through the interface file, it'll make sense.

If "Repeat" is checked, obvious it'll keep repeating the entered key, which is useless for the example I have shown (repeat is useful for things that needs it to be repeated, like movement).

If "When key is released" is checked, whatever command is there will be called when the key is released.

If you are talking about the A in "KeyDown A" and "KeyUp A", "A" is actually the argument being sent.

So for 'B', it'll be "KeyDown B" and "KeyUp B".

Edit:
KeyDown(T as text)
keys[T]=1
if(keys["W"] && keys["T"] && keys["F"]) // If the keys W, T and F are pressed:
world << "O NOEZ!"

else if(keys["O"] && keys["M"] && keys["G"]) // OMG
shutdown()
In response to GhostAnime
I guess I'll once again attempt to delve into the complex mess that is BYOND interfaces for the first time since a little after 4.0 was released..

Thanks, though. Even if it will require me to learn an entirely new branch of BYOND, I guess it's a feature that BYOND is already capable of.
In response to Mechana2412
It's not all that complex at all. Especially not the macros area, which is all you currently need to mess with. There's nowhere to "delve" to, really, you'll be diving into an empty pool. =P Using macros is simple compared to using interface controls.
In response to Kaioken
I just found out how to use the macros, actually alot simpler than I thought it would be, but now I need to use a custom interface. Is there any way I can disable an interface file's actual interface?
In response to Mechana2412
Rephrasing what you said, what you want to to is just 'to use the default interface just with added X', X in our case being macros. For information on how to do that, read this topic.
In response to Kaioken
I was thinking of doing that, but I was just making sure there wasn't an easier way to do it. Thanks!