ID:1951953
 
(See the best response by Kaiochao.)
Code:
winset(src,"default.map1","focus=TRUE")


Problem description:

I'm using forum_account's keyboard lib but when I press a macro it keeps switching to the chat pane and putting the macro letter in the chat box.
I've tried the code above but nothing changes.
That's a sign that your letter macros aren't actually being set. Maybe set_macros() isn't being called somehow (unlikely), or your interface doesn't actually have a macro set, or your default window doesn't use any macro set.
Okay, I've gotten it to start running but when you release the button you dont stop running.
mob/Player
Login()
..()
icon = 'Player.dmi'
icon_state = "Walk"
src.addname("[src.key]")
loc = locate (51,13,1)
src << output("<font size=2><center> Controls:<br><br> Arrow keys= Movement<br><br>Space= Get Dodgeball<br><br>R= Run<br><br>Throw= </font></center>","output1")
new/maptext("<font size=3>Welcome to</font>", "CENTER - 1 : 17, SOUTH + 5", "Login New", 96, 220, mo=2)
new/maptext("<font size=3>Dodgeball Online!</font>", "CENTER - 1 : 17, SOUTH + 5", "Login New", 96, 200, mo=2)
spawn(50)
src.Delete_Maptext()
winset(src,"default.map1","focus=TRUE")
key_down(k)
if(k == "r")
Run()
key_up(k)
if(k == "r")
Run2()


mob
proc
Run()
set hidden=1
src.step_size = 10
src.icon_state = "run"

Run2()
set hidden=1
src.step_size = 8
src.icon_state = ""


mob/Player/verb
Start()
if(src.key=="Edit Nero")
DodgeBall()
else
src << "You can't use this!"

OOC(txt as text)
if(src.Team=="Red")
world << output("<font color=red>(Red Team)[src.key]</font>: [txt]","output1")
return
if(src.Team=="Blue")
world << output("<font color=blue>(Blue Team)[src.key]</font>: [txt]","output1")
return
else
world << output("<font color=yellow>(Lobby)[src.key]:</font> [txt]","output1")
return

Run1()
src.Run()
Run3()
src.Run2()
In response to Edit Nero
Sounds like a different problem. Can you confirm that key_down() and key_up() are being called on whatever your client.focus is (defaults to client)?
I profiled it and key_down() nor key_up() are being called.
In response to Edit Nero
By the way, if you make sure all your windows have the same macro set, macros will always be processed the same unless focus is on a text input, so you usually don't need to winset() focus.

So Forum_account's Keyboard library has a client variable called "focus" that determines which datum gets the keyboard events. If you want the player mob's key_down() and key_up() to happen, you have to set the client's focus to the mob, like so:
mob/Player
Login()
..()
client.focus = src
I did, they still aren't being called.
I dont know if this will have an impact on your problem or not, but I can tell you that TRUE has to be true.
winset(src,"default.map1","focus=TRUE")//doesnt work
winset(src,"default.map1","focus=true")//works


Its an odd little inconsistency.
Yeah, well. It's not even calling the procs so.
In response to Edit Nero
Im really curious how you get the mob to start running with run(), but key_down() isn't being called?
Nope
In response to Edit Nero
Nope-what? It wasn't a yes or no question.

Okay, I've gotten it to start running but when you release the button you dont stop running.
How are you getting the mob to run without key_down() being called?
In response to ZOMGbies
Nope, it isn't being called.

With recent changes, it doesn't run anymore. No proc is being called. I made a verb to manually do it but I would like the lib to run properly instead.
In response to Edit Nero
If key_down/up isn't being called, then you just follow the trail back one level. Which is checking whether set_macro is working as it should. Work out what you've changed about it, to fit into your code, or what you might not have changed.

It would be nice to see your version of set_macro() pasted here.

I know that in FA's version, he uses the default macro list known as "macro". Does your project use a custom interface at all? If so, maybe provide a screenshot of that file once opened (where it lists all the windows/panes/menus and macros.

Also:
With recent changes, it doesn't run anymore.
Which changes are they?
No, I haven't changed the interface. I copy pasted the lib and put the keydowns in my login code but they aren't being called. I can't post the code atm, I'm not at home.
...put the keydowns in my login code
If you mean like this
Login()
key_down("r")

and its still not being called, then it sounds like theres a runtime error or something crashing the proc. If this is the case, check your world.log (options messages window/press F1 on default macros)
I'll have to check when I'm able which will be 2 hours. But I'm pretty sure it's not causing any runtime errors.
client
var
// map keys to the client procs they call
__default_action = list(
"north" = "North",
"south" = "South",
"east" = "East",
"west" = "West",
"southeast" = "Southeast",
"southwest" = "Southwest",
"northeast" = "Northeast",
"northwest" = "Northwest",
"center" = "Center",
"Run" = "r")

// we have to define these procs here because clients don't
// inherit from /datum.
proc
key_up(k, client/c)

key_down(k, client/c)
__default_action(k)

#ifndef NO_KEY_REPEAT
key_repeat(k, client/c)
__default_action(k)
#endif

#ifndef NO_CLICK
click(object, client/c)
#endif

__default_action(k)
// if the key has a default action, trigger it
if(k in __default_action)
var/proc_name = __default_action[k]
call(src, proc_name)()
Dude. What the hell is this? I asked for set_macro and a screenshot of your dmf file.

Maybe that's the reason keydown isnt working. You dont have set_macro() in your code.
It wasn't in the lib so I didn't know
Page: 1 2