User File #26318138254340419

Upload All User Files

#26318138254340419 - Simple JPC-rr Mouse Script

JPCMouse.lua
System: DOS
841 downloads
Uploaded 10/21/2015 5:26 AM by slamo (see all 61)
This is an extremely simple lua script for use in JPC-rr to facilitate mouse movement. There is also a display for which mouse buttons are currently triggered - make sure you have version 11.8-rc2 or later otherwise this display won't work.
Here are the movement commands.
movex i - Move the mouse "i" units in the x direction.
movey j - Move the mouse "j" units in the y direction.
moveb i j - Move the mouse "i" units in the x direction and "j" in the y direction.
dofile("textrender.lua");


while true do
	mtype, message = jpcrr.wait_event();
	if mtype == "lock" then
		mouseinfo = jpcrr.status();
		jpcrr.hud.bottom_gap(3, 16);
		if mouseinfo.mouse_button_1 then
			mouse1 = 255
		else
			mouse1 = 50
		end
		if mouseinfo.mouse_button_2 then
			mouse2 = 255
		else
			mouse2 = 50
		end
		if mouseinfo.mouse_button_3 then
			mouse3 = 255
		else
			mouse3 = 50
		end
		render_text(3, 100, 400, "LEFT", false, 0, mouse1, 0);
		render_text(3, 200, 400, "MIDDLE", false, 0, mouse2, 0);
		render_text(3, 300, 400, "RIGHT", false, 0, mouse3, 0);
		jpcrr.release_vga();
	elseif mtype == "message" then
		c,d,e = string.match(message, "(.*) (.*) (.*)");
		C,D = string.match(message, "(.*) (.*)");
		if message == "hi" then
			print("hi");
		elseif e and c == "moveb" then
			if string.match(d, "-?[0-9]+") and string.match(e, "-?[0-9]+") then
				print("Moved X "..tonumber(d).." and Y "..tonumber(e));
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "XMOUSEMOTION", tonumber(d));
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "YMOUSEMOTION", tonumber(e));
			end
		elseif D and C == "movex" then
			if string.match(D, "-?[0-9]+") then
				print("Moved X "..tonumber(D));
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "XMOUSEMOTION", tonumber(D));
			end
		elseif D and C == "movey" then
			if string.match(D, "-?[0-9]+") then
				print("Moved Y "..tonumber(D));
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "YMOUSEMOTION", tonumber(D));
			end
		end
	end
end