InKey$

Just starting out? Need help? Post your questions and find answers here.
ltrail
New User
New User
Posts: 8
Joined: Thu Dec 27, 2012 9:06 pm

InKey$

Post by ltrail »

Am I correct that this tool has not been clearly defined in the documentation? I don't have a clue as to how to use it, in programs. Nothing is shown as to its attributes either. Does someone know it well? May I have some clue as to its power? Thanks.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: InKey$

Post by Tenaja »

That sounds like a retro command. Look at Inkey() and its use:
String$ = Inkey()
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: InKey$

Post by Nituvious »

Inkey() is a console function.

Code: Select all

OpenConsole()

Print("What is your name? ")

While (1) : Delay(1)
	
	key.s = Inkey()
	
	If RawKey() <> 13
		If key <> ""
			name.s + key
			Print(key)
		EndIf
	Else
		PrintN("")
		Break
	EndIf

Wend

If name.s <> ""
	PrintN("Good to meet you, " + name.s)	
EndIf

PrintN(#LF$ + "Press any key to quit...")
Input()

▓▓▓▓▓▒▒▒▒▒░░░░░
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: InKey$

Post by vwidmer »

Should this work on OSX it doesnt seem to show anything I also tried

Code: Select all

If OpenConsole ()
  PrintN("Press Escape to exit")
  Repeat
    KeyPressed$ = Inkey() 
    If KeyPressed$ <> ""
      PrintN("You pressed: " + KeyPressed$) 
      PrintN("It has a raw code of: "+Str(RawKey()))
    ElseIf RawKey ()
      PrintN("You pressed a non ASCII key.")
      PrintN("It has a raw code of: "+Str(RawKey()))
    Else
      Delay(20) ; Don?t eat all the CPU time, we?re on a multitask OS 
    EndIf
    Debug KeyPressed$
    ;Debug i
    ;i = i + 1
  Until KeyPressed$ = Chr(27) ; Wait until escape is pressed 
EndIf
it also is not showing any key press. I have tried it in the IDE and also compiled.

I need program to just wait for a key press.

Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: InKey$

Post by ts-soft »

@vwidmer

for using in the IDE set CompilerOption to console!
for using the executable, open a terminal
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: InKey$

Post by Danilo »

ts-soft wrote:for using the executable, open a terminal
If you double-click a console program, it opens a terminal and runs.
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: InKey$

Post by vwidmer »

Sorry for not a clear question. I am not having a problem running it. I understand about using the console and terminal and compiling.

The problem I am having is that the keys are not being shown or captured. Unless I press a key a second after launching then it will recognize but if I wait a sec nothing seems to capture.

Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: InKey$

Post by vwidmer »

I tried it running in winXP and Linux and it seems to work fine just not on my OSX system any one else can try it on osx?

Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
Post Reply