Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
SuperSamir

Touch input

Question

I'm using event.listen("touch") to make wherever I touch to be where the cursor is. However, this only writes the cursor's state on the cursor, and leaves the cursor in the same place it was before. I would like the cursor to move where I click, and be able to write text from there, instead of just leaving the cursor state there.

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Each process in openos has its own instance of a cursor. It's stored in the window property of a process I believe.. try assigning to the processes window cursor as term.setCursor will only set the cursor of the process calling it... I can't test any code ATM so you may have some exploring to do

Share this post


Link to post
Share on other sites
  • 0

okay so its a bit tricky cause i dont know what exactly you're trying to pull but ill give it a shot...

local term = require "term"
local kb = require "keyboard"
local event = require "event"
local process = require "process"
local component = require "component"

local window = term.internal.open() -- # creates a full screen window. optionally provide (dx, dy, width, height)
term.bind(component.gpu, window) -- # bind the primary gpu to the window we made

local proc = process.info() -- # get an instance of this process' details
local handle = event.listen("touch", function(_, _, x, y) -- # this is basically your 'cursor' function
    	proc.data.window.x = x
    	proc.data.window.y = y
    	print "HI" -- # click around to see the effect
    end)

while true do
  local ev = {event.pull("key")}
  if ev[4] == kb.keys.q then break end -- # quit the loop and basically the program
end

event.cancel(handle) -- # clear the event listener

This example can be modified to control the window of another process as well. I hope this can get you started. Ask away if this isn't very clear....

Share this post


Link to post
Share on other sites
  • 0

Was this any help? I forgot, but there is actually a cursor library in the later versions of openos that you might want to check out.. I haven't used it and I'm not familiar with it at all but that might be a better solution.

Share this post


Link to post
Share on other sites
  • 0

The method you have provided seems to work, which I thank you for. Please do tell me about this cursor library though, I can't seem to find it but it seems like a massive help for the thing I'm programming.

Share this post


Link to post
Share on other sites
  • 0

The lib you're looking for are cursor.lua & full_cursor.lua but I'm not sure these will do what you're seeking to accomplish I just remember hearing about them...

Also my example was done in a way that it could be modified to control the windows(and thus the cursors) of other processes. If you just want to access the current processes window it  may be simpler with the tty lib.

local tty = require "tty"
local event = require "event"
local kb = require "keyboard"

local window = tty.window
local handle = event.listen("touch", function(_, _, x, y)
    	window.x = x
    	window.y = y
    	print "HI"
    end)

while true do
  local ev = { event.pull("key", nil, nil, kb.keys.q) }
  event.cancel(handle)
  break
end

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.