mirror of
				https://github.com/LDDestroier/CC/
				synced 2025-10-31 07:22:59 +00:00 
			
		
		
		
	Fixed output of keypress.resume(...), fixed indenting
This commit is contained in:
		
							
								
								
									
										37
									
								
								keypress.lua
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								keypress.lua
									
									
									
									
									
								
							| @@ -97,7 +97,7 @@ local modfier_lookup = { | ||||
| function keypress.resume(...) | ||||
|  | ||||
| 	local evt = {...} | ||||
| 	local output1, output2 | ||||
| 	local output = {} | ||||
|  | ||||
| 	if evt[1] == "keypress" and _DEMO then | ||||
| 		-- exit demo with CTRL-C | ||||
| @@ -106,10 +106,19 @@ function keypress.resume(...) | ||||
|  | ||||
| 		else | ||||
| 			print("key  = keys." .. (r_keys[evt[2]  .key] or "???")) | ||||
| 			write("char = " .. (evt[2].char or "nil")) | ||||
| 			 | ||||
| 			if evt[2].char then | ||||
| 				write("char = '" .. evt[2].char .. "'") | ||||
| 			else | ||||
| 				write("char = nil") | ||||
| 			end | ||||
|  | ||||
| 			if evt[2].char_pressed then | ||||
| 				print(" (" .. evt[2].char_pressed .. ")") | ||||
| 			else print("") end | ||||
| 				print(" ('" .. evt[2].char_pressed .. "')") | ||||
| 			else | ||||
| 				print("") | ||||
| 			end | ||||
|  | ||||
| 			print("note = " .. (evt[2].notation or "(NONE)")) | ||||
| 			write("mods = ") | ||||
| 			write(evt[2].ctrl and "ctrl " or "") | ||||
| @@ -122,10 +131,9 @@ function keypress.resume(...) | ||||
| 		keys_down[evt[2]] = true | ||||
| 		modifier_keydowns() | ||||
|  | ||||
| 		if nonprintable_keys[evt[2]] or ( | ||||
| 			keys_down[keys.ctrl] or keys_down[keys.alt] | ||||
| 		) then | ||||
| 		output1, output2 = "keypress", { | ||||
| 		if nonprintable_keys[evt[2]] or (keys_down[keys.ctrl] or keys_down[keys.alt]) then | ||||
| 			output[1] = "keypress" | ||||
| 			output[2] = { | ||||
| 				key = evt[2], | ||||
| 				char = nil, -- represents a printable character -- use this if you're using keypress API for text input | ||||
| 				char_pressed = nil, -- represents the character pressed regardless of if it should print | ||||
| @@ -135,7 +143,7 @@ function keypress.resume(...) | ||||
| 				alt = keys_down[keys.alt] | ||||
| 			} | ||||
|  | ||||
| 		output2.notation = keypress.to_vim_notation(output2) | ||||
| 			output[2].notation = keypress.to_vim_notation(output[2]) | ||||
| 		else | ||||
| 			last_epoch = os.epoch() | ||||
| 			last_key = evt[2] | ||||
| @@ -148,7 +156,8 @@ elseif evt[1] == "key_up" then | ||||
| 	elseif evt[1] == "char" and last_evt == "key" then | ||||
| 		delta = os.epoch() - last_epoch | ||||
| 		if delta <= 90 then | ||||
| 		output1, output2 = "keypress", { | ||||
| 			output[1] = "keypress" | ||||
| 			output[2] = { | ||||
| 				key = last_key, | ||||
| 				char = evt[2], | ||||
| 				char_pressed = evt[2], | ||||
| @@ -158,16 +167,20 @@ elseif evt[1] == "char" and last_evt == "key" then | ||||
| 				alt = keys_down[keys.alt] | ||||
| 			} | ||||
|  | ||||
| 		output2.notation = keypress.to_vim_notation(output2) | ||||
| 			output[2].notation = keypress.to_vim_notation(output[2]) | ||||
| 		end | ||||
|  | ||||
| 	else | ||||
| 		last_key = nil | ||||
| 	end | ||||
|  | ||||
| 	if #output == 0 then | ||||
| 		output = evt | ||||
| 	end | ||||
|  | ||||
| 	last_evt = evt[1] | ||||
|  | ||||
| return output1, output2 | ||||
| 	return table.unpack(output) | ||||
| end | ||||
|  | ||||
| -- convert some key codes to characters | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 LDDestroier
					LDDestroier