local currentX = 1
local currentY = 1
These will set the cursor position.
function drawCursor()
term.clear()
term.setCursorPos(currentX, currentY)
write(">")
end
This will draw the cursor at the current x/y, now that we got that, we need to call drawCursor() and add controls like this:
while true do
drawCursor()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
currentY = currentY -1
elseif key == 31 or key == 208 then --down
currentY = currentY +1
elseif key == 203 or key == 30 then --left
currentX = currentX -1
elseif key == 205 or key == 32 then --right
currentX = currentX +1
end
end
If you put all this code together like this:
local currentX = 1 --Saves the current X of the cursor
local currentY = 1 --Saves the current Y of the cursor
function drawCursor()
term.clear() --Clears the screen
term.setCursorPos(currentX, currentY) --Draws a cursor at the current X/Y
write(">")
end
while true do
drawCursor()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
currentY = currentY -1
elseif key == 31 or key == 208 then --down
currentY = currentY +1
elseif key == 203 or key == 30 then --left
currentX = currentX -1
elseif key == 205 or key == 32 then --right
currentX = currentX +1
end
end
It will create a cursor that can move left and right.
If you wan't to make options in a menu, remove the left and right and keep up/down and make it so if the cursor is at the same position of the button, make it open the button.
This is how I did it in my WinOS. You can look at that source for more information.
To change the cursor, in drawCursor(), edit write(">") and change it to write("your cursor")