get_key Processing

new topic     » topic index » view thread      » older message » newer message

I am trying to accept a single key from the keyboard without having to press the <cr> button, convert the key code to an upper case command character and then process the character to perform the appropriate actions. The code below results in the menu line being displayed but nothing is accepted and I have to ctl-C out of the program. I'm sure I'm doing something really stupid but for the life of me I can't figure out what it is so wanted to ask sharper minds than mine for ideas and suggestions. And yes, this is 'dirty' code which I'll clean up in a switch statement but I wanted to get it working first.

Here is the code and thanks in advance for any thoughts on what I'm doing wrong:

-- prompt the user for his command 
    clear_screen() 
    puts(SCREEN, "Simple TC ARES Database\n") 
    while TRUE do 
		puts(SCREEN,  
			"\n(a)dd, (c)ount, (d)elete, (e)dit, (f)ind, (l)ist, (p)rint, (r)eport, (q)uit: ") 
		 
		while 1 do	  
			integer code = get_key() 
			if code != -1 then 
			         
				command = 'Z' 
			 
				if code = 65 or code = 97 then 
					command = 'A' 
				elsif code = 67 or code = 99 then 
					command = 'C' 
				elsif code = 68 or code = 100 then 
					command = 'D' 
				elsif code = 69 or code = 101 then 
					command = 'E' 
				elsif code = 70 or code = 102 then 
					command = 'F' 
				elsif code = 76 or code = 108 then 
					command = 'L' 
				elsif code = 80 or code = 112 then 
					command = 'P' 
				elsif code = 82 or code = 114 then 
					command = 'R' 
				elsif code = 81 or code = 113 then 
					command = 'Q' 
					 
				end if 
			end if 
		 
		end while 
		 
		if command = 'A' then 
		        add() 
		elsif command= 'C' then 
		        show_count(SCREEN) 
		elsif command = 'D' then 
		        delete() 
		elsif command = 'E' then 
		        edit_record() 
		elsif command = 'F' then 
		        find_name() 
		elsif command = 'Q' then 
		        exit 
		elsif command = 'R' then 
		        report(SCREEN) 
		elsif command = 'L' then 
		        list(SCREEN) 
		elsif command = 'P' then 
		        printer = open("PRN", "w") 
			if printer = -1 then 
				puts(SCREEN, "Can't open printer device\n") 
			else 
				list(printer) 
				puts(printer, FORM_FEED) 
				close(printer) 
			end if 
		else 
			puts(SCREEN, "\n\nInvalid Command:  " & command & "\n") 
		end if 
		 
			  
 
    end while 

Tom

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu