separate( seven )

procedure getKeyInputs( mainWin : access GLFWwindow ) is

	deltaTime,
	nowTime : gldouble;
	xpos,ypos : aliased gldouble;

	zmin: constant double := zoomwheel.zmin;
	zmax: constant double := zoomwheel.zmax;
	sel,dir: character;
begin

	nowTime := glfwGetTime;
	deltaTime := nowTime - oldTimeKb;



-- First, we process continuous key-press responses:-----------------

if glfwgetkey( mainWin, glfw_key_escape ) = Glfw_Press then
		userexit:=true;

elsif glfwgetkey( mainWin, glfw_key_q ) = Glfw_Press then
		userexit:=true;

--zoom In
elsif glfwgetkey( mainWin, glfw_key_i ) = Glfw_Press then
			zoomwheel.zdist:=0.999*zoomwheel.zdist;
			if zoomwheel.zdist<zmin then zoomwheel.zdist:=zmin; end if;

--zoom Out
elsif glfwgetkey( mainWin, glfw_key_o ) = Glfw_Press then
			zoomwheel.zdist:=1.001*zoomwheel.zdist;
			if zoomwheel.zdist>zmax then zoomwheel.zdist:=zmax; end if;



-- Second, we process discrete key-press events -----------------------

elsif deltaTime > keydlay then 

	nowTime := glfwGetTime;

-- AXES comparison seven versus cube:
-- seven		cube
--		Z		Y
--		Y		X
--		X		Z
-- (see seven-cubic versus cube-cubic)

	-- +Y cube
	--if glfwgetkey( mainWin, glfw_key_up ) = Glfw_Press then
	-- +Z seven
	if glfwgetkey( mainWin, glfw_key_f ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		moveYp;
		oldTimeKb := nowTime;

	-- -Y cube
	--elsif glfwgetkey( mainWin, glfw_key_down ) = Glfw_Press then
	-- -Z seven
	elsif glfwgetkey( mainWin, glfw_key_b ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		moveYm;
		oldTimeKb := nowTime;


	-- -X cube
	--elsif glfwgetkey( mainWin, glfw_key_left ) = Glfw_Press then
	-- -Y seven
	elsif glfwgetkey( mainWin, glfw_key_down ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		moveXm;
		oldTimeKb := nowTime;

	-- +X cube
	--elsif glfwgetkey( mainWin, glfw_key_right ) = Glfw_Press then
	-- +Y seven
	elsif glfwgetkey( mainWin, glfw_key_up ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		moveXp;
		oldTimeKb := nowTime;


	-- -Z, Backward cube
	--elsif glfwgetkey( mainWin, glfw_key_b ) = Glfw_Press then
	-- -X seven
	elsif glfwgetkey( mainWin, glfw_key_left ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		moveZm;
		oldTimeKb := nowTime;

	-- +Z, Forward cube
	--elsif glfwgetkey( mainWin, glfw_key_f ) = Glfw_Press then
	-- +X seven
	elsif glfwgetkey( mainWin, glfw_key_right ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		moveZp;
		oldTimeKb := nowTime;



	-- Restart
	elsif glfwgetkey( mainWin, glfw_key_r ) = Glfw_Press then
		haveSolution:=0;
		nsol:=0;
		restart;
		oldTimeKb := nowTime;




	elsif glfwgetkey( mainWin, glfw_key_m ) = Glfw_Press then
		mute:=not mute;
		oldTimeKb := nowTime;



	elsif glfwgetkey( mainWin, glfw_key_1 ) = Glfw_Press then
		shuffle(1);
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_2 ) = Glfw_Press then
		shuffle(2);
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_3 ) = Glfw_Press then
		shuffle(3);
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_4 ) = Glfw_Press then
		shuffle(4);
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_5 ) = Glfw_Press then
		shuffle(5);
		oldTimeKb := nowTime;


	elsif glfwgetkey( mainWin, glfw_key_h ) = Glfw_Press then
		help:=not help;
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_a ) = Glfw_Press then
		show_axes:=not show_axes;
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_space ) = Glfw_Press then
		hint:=not hint;
		oldTimeKb := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_x ) = Glfw_Press then
		dump:=not dump;
		oldTimeKb := nowTime;


	elsif glfwgetkey( mainWin, glfw_key_c ) = Glfw_Press then
		origskin:=not origskin;
		oldTimeKb := nowTime; --prepare for next time
		if origskin then
			glfwsetwindowtitle(mainwin,otitle);
		else
			glfwsetwindowtitle(mainwin,vtitle);
		end if;


	elsif

		(glfwgetkey( mainWin, glfw_key_s ) = Glfw_Press)
		--	or
		--(glfwgetkey( mainWin, glfw_key_equal ) = Glfw_Press)

	then


		oldTimeKb := nowTime;

		-- solve one step at a time:
		if haveSolution>0 then

			nsol:=0; --disable shuffle-undo

			sel:=element(solutionPath,1); --possibly not needed?
			dir:=element(solutionPath,3);
			delete(solutionPath,1,3);
			haveSolution := length(solutionPath);

			if dir='l' then
				moveXm; --moveleft;
			elsif dir='r' then
				moveXp; --moveright;
			elsif dir='u' then --inverted due to screen Y vs OGL
				moveYm; --moveup;
			elsif dir='d' then -- inverted due to screen Y vs OGL
				moveYp; --movedown;
			elsif dir='b' then
				moveZm; --movenear;
			elsif dir='f' then
				moveZp; --moveaway;
			else
				--raise program_error;
				haveSolution:=0;
			end if;

		else -- initiate solver

			failureNotice:=false;

			permdump("7.blok"); --experiment 27feb21
			bfs7.bfs(to_unbounded_string("7.blok"),solutionPath);
			haveSolution := length(solutionPath);

		end if;




	elsif 
		(glfwgetkey( mainWin, glfw_key_equal ) = Glfw_Press)
	then

		oldTimeKb := nowTime;
		haveSolution:=0; --cancel solver

		-- solve one step at a time:
		if nsol>0 then

			put_line(integer'image(nsol)&" steps to solution.");

			s:=sol(nsol); nsol:=nsol-1;
			if s=lf then
				moveXm; --moveleft;
			elsif s=rt then
				moveXp; --moveright;
			elsif s=up then -- inverted due to screen Y vs OGL
				moveYm; --moveup;
			elsif s=dn then -- inverted due to screen Y vs OGL
				moveYp; --movedown;
			elsif s=nr then
				moveZm; --movenear;
			elsif s=aw then
				moveZp; --moveaway;
			else
				raise program_error;
			end if;

		end if;





	elsif glfwgetkey( mainWin, glfw_key_enter ) = Glfw_Press then
		oldTimeKb := nowTime;
		glfwgetcursorpos(mainWin,xpos'access,ypos'access);
		clickRight(xpos,ypos,gldouble(winwidth),gldouble(winheight));


	end if;

end if;

end getKeyInputs;





