Page 1 of 1

keyboardpushed(#PB_Any_Letter)

Posted: Thu Jun 20, 2019 10:04 pm
by bfernhout
When i put in a code e.g.

Code: Select all

TheKey = KeyboardPushed(#PB_Key_RightAlt)
The result is 128 and not 1 if key is pressed.

The description say non zero. And the bottum line say 1 if key is pressed.
In bitwize notation 128 is bit number 7. and not bit number 0.

Was this a intention or is there something wrong here ?

Re: keyboardpushed(#PB_Any_Letter)

Posted: Thu Jun 20, 2019 11:58 pm
by BarryG
I don't know what "bottom line" you're talking about, but the manual says: "Nonzero if the specified key is pushed, zero otherwise."

So, as Metallica says: nothing else matters. Test for zero or non-zero only to make it work as documented and intended.

Re: keyboardpushed(#PB_Any_Letter)

Posted: Sun Jun 23, 2019 7:03 pm
by bfernhout
Sorry i was under the impression that i already replyed.

When you are in the IDE and type in
KeyboardPushed(...
You see at the bottom line the short explenation of using the function.
And that says: KeyboardPushed(KeyID) Returns a 1 if the assinged key is pressed. otherwise 0.

So you may think that the pressing of the key, gives you a 1 like #True. But i got a 128 value returned.
That put me on the wrong foot. When i try to write some code and you see the bottom line. you make up the wrong code.

Now i know that the last bit is set and not the first i can work with that. Every key give back a 128 value (Bit#7 is a 1). This is easy to convert to a 1 value (Bit #0 is a 1)
By making a procedure testing the key and give back the value i need.

Thanks guy's

Re: keyboardpushed(#PB_Any_Letter)

Posted: Sun Jun 23, 2019 7:23 pm
by Derren
True. The quick-tip in the IDE differs from the help file.
Case for bugs: Documentation viewforum.php?f=37

I posted the mistake: viewtopic.php?f=37&t=73080

Re: keyboardpushed(#PB_Any_Letter)

Posted: Mon Jun 24, 2019 12:02 am
by BarryG
bfernhout wrote:You see at the bottom line the short explenation of using the function.
And that says: KeyboardPushed(KeyID) Returns a 1 if the assinged key is pressed. otherwise 0.
Oh, bottom line = status bar of the IDE. Yes, it says something different to the Help. Now I get what you mean.

Re: keyboardpushed(#PB_Any_Letter)

Posted: Tue Jul 16, 2019 9:16 am
by bfernhout
Thanks for the post.
It is something that can bring new people on the wrong foot.

Still this is the best way to make programs. If I make the same program in C++, then they are alway larger and slower. I talk about say Purebasic run a program on 300 ms and the compiled and optimized c++ runs on a avarage of 380 ms.
Only when i make the program in Assembler the compiling create a smaller program and run faster.

But then again PB is beter and easyer to program.