Keyboard sensor question

(fve) #1

Hi,

I am looking for a detailed description of the keyboard sensor.
Want to find out wether it is responsible for the following:

Console output apears twice.(When ‘pressing’, as well as when ‘releasing’ the related key)

Greetings,

Frans.

0 Likes

(Duoas) #2

All keyboards send two signals per key: the make code when the key is pressed and the break code when released. This usually translates to the key-down and key-up sensor events.

If you don’t want double of everything, make sure not to print the key in one of the events.

Hope this helps.

0 Likes

(fve) #3

Duoas thank you.

You wrote: ‘If you don’t want double of everything, make sure not to print the key in one of the events.’

Is this related with the Pulse Mode Buttons settings of the keyboard sensor?
Or how else should I make sure NOT to print the key in one of the events?

Frans.

0 Likes

(ashsid) #4

Double output on console doesn’t have anything to do with keyboard sensors and keyboard events. It happens because every change of any sensor causes running of controller script. You have to check in controller script, if condition for running script is met.
For example script is run when all sensors are active:

contr = GameLogic.getCurrentController()
for sens in contr.getSensors():
  if not sens.isPositive(): break
else:
  # rest of the script
  print 'running script'

0 Likes

(fve) #5

Thanks ashid, I shall look into that.

Greetings.

0 Likes

(fve) #6

I can’t get it to work because I miss the clue of what you are telling me.
Maybe you would be so kind to point me to some documentaion involved.

With respect,

Frans

0 Likes

(ashsid) #7

SCA_ISensor documentation
If you replace line after “# rest of the script” from my example with your actual script (properly intended), it will be executed only when key will be pressed.

0 Likes

(fve) #8

Sorry Ashid for delay,

Can’t get it going yet, but I’ll keep trying.

Thank you for documentation.

Frans.

0 Likes