keyboardpushed(#PB_Any_Letter)

Everything else that doesn't fall into one of the other PB categories.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

keyboardpushed(#PB_Any_Letter)

Post 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 ?
From my first self made computer till now I stil like computers.
BarryG
Addict
Addict
Posts: 3293
Joined: Thu Apr 18, 2019 8:17 am

Re: keyboardpushed(#PB_Any_Letter)

Post 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.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: keyboardpushed(#PB_Any_Letter)

Post 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
From my first self made computer till now I stil like computers.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: keyboardpushed(#PB_Any_Letter)

Post 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
BarryG
Addict
Addict
Posts: 3293
Joined: Thu Apr 18, 2019 8:17 am

Re: keyboardpushed(#PB_Any_Letter)

Post 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.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: keyboardpushed(#PB_Any_Letter)

Post 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.
From my first self made computer till now I stil like computers.
Post Reply