ID:1910746
 
Hey guys,

So I admit I didn't search too deeply for info on this, but i'm grateful for any insight that might be provided from this fine community.

I'd like to add a feature to the command line / input bar, where it could remember the previously entered command. The player can simply hit enter repeatedly and carry on using the last command that was entered.

I do already have it functioning that players can press the up arrow and recall previous commands, but it would be more helpful if they could simply press enter repeatedly. It would also be a huge benefit if the command could re-appear highlighted, so that when they wish to enter a new command, they need only type and not have to delete said previous entry.

I'd love to get some help on this if it's possible, and any idea's are appreciated.

Thanks in advance!
Hey, let me see if I understood what you are saying:

1st. The player writes a command in the input bar
2nd. The command that the player wrote is memorized
3rd. The player presses enter and the command appears highlighted in the input bar.

I am assuming that the input bar that you are talking about is the default one (you didn't create a new interface file).

So this is an option:
mob/Player/Login()
SetDection()
..()

mob/Player/var/tmp/LastCommand

mob/Player/verb/ooc(t as text)
world<<t
LastCommand = "ooc"

mob/Player/proc/SetDection()
winset(src, "M1", "parent=macro;name=Return;command=GetInformation") //Return = Enter key

mob/Player/verb/GetInformation()
set hidden = 1
var/GET_TEXT = winget(src,"mainwindow.input","text") //This will get the current text in the input bar (So if you are writing a chat message it won't get deleted)
if(length(GET_TEXT) == 0 && LastCommand <> null)
winset(src,"mainwindow.input",list2params(list("focus"=1))) //This will focus the input bar so there is no need for the client to manualy select it.
winset(src,"mainwindow.input","text=\"[LastCommand]\"") //This will write the last command in the input bar

In order to higlight the text you need to simulate a combo key press SHIFT+HOME. That can be achieved with javascript:
        var/SCRIPT = {"
<!DOCTYPE html>
<html>
<script>

var e= document.createEvent("KeyboardEvent");
e.initKeyboarEvent("keydown", true, true, null , false, false, true, false, 36, 0); //This should be initKeyboardEvent because the byond browse uses internet explorer
'byond://winget?id=mainwindow.input'.dispatchEvent(e);
</script>
</html>
"}

src<<browse(SCRIPT) //This should be a hidden browser



//EDIT:::: OR you can use JQuery here

<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script type="text/javascript">
$(byond://winget?id=mainwindow.input).trigger("select");
</script>

</body>
</html>


I don't know why but my javascript code isn't working... I've posted a topic about this in stackoverflow (feel free to follow it)
http://stackoverflow.com/questions/31843205/ javascript-key-simulation-isnt-working


After a lot of research I found this topic http://www.byond.com/ forum/?post=1755334&hl=fireMacro#comment13453362 and Lumox talked about a byond.fn.fireMacro() procedure. I'm
not sure how it works though (or even if it can do what we want it to do). But don't worry, I'm sure that he will check this post and he'll help us with it.

Sorry for only help you solving half of the problem... I really don't know how to highlight the text on the input bar...