all keys except ___


(d52477001) #1

hi,

i want to create a logic brick where something happens if you press any key except for a few certain ones. is there any way to do this? maybe it is possible using nor in the controller? i don’t know how to get a nor expression so i can’t try. Any suggestions?

thanks

d52477001


(Abracsis) #2

Use a Keyboard sensor with AllKeys, linked to an AND sensor.

Then create a keyboard sensor for each key you don’t want it to work for, and click INV in the top right of the sensor box for each.

Link these up to the same controller and bingo.

One thing…you may have to play with True/false pulse modes (those buttons with dots on, and of course python wud propabal be more efficient.

-Luke


(d52477001) #3

ok thanks…

how do i do it in python?


(saluk) #4

c = GameLogic.getController()
keys = c.getSensor("allkeys")  #connected to the all keys sensor
if keys.isPositive():
   keypressed = 0
   for key in keys.getPressedKeys():
      if key[0] == YOURNUMBER:
         keypressed = 1
   if keypressed == 0:
      YOURCODE

To see what number your key is, add this line before keypressed = 1: print key[0]. Then run the game, press your bad key, and see what number it is. Replace YOURNUMBER with the number for that key.


(z3r0 d) #5

I didn’t read the code (posted just above this post)… but I believe you can get to the key number in a more clear way (for those skimming the code) by using the GameKeys Module…

GameKeys.ACCENTGRAVEKEY
GameKeys.AKEY
GameKeys.BACKSLASHKEY
GameKeys.BACKSPACEKEY
GameKeys.BKEY
GameKeys.CAPSLOCKKEY
GameKeys.CKEY
GameKeys.COMMAKEY
GameKeys.DELKEY
GameKeys.DKEY
GameKeys.DOWNARROWKEY
GameKeys.EIGHTKEY
GameKeys.EKEY
GameKeys.ENDKEY
GameKeys.EQUALKEY
GameKeys.ESCKEY
GameKeys.F10KEY
GameKeys.F11KEY
GameKeys.F12KEY
GameKeys.F1KEY
GameKeys.F2KEY
GameKeys.F3KEY
GameKeys.F4KEY
GameKeys.F5KEY
GameKeys.F6KEY
GameKeys.F7KEY
GameKeys.F8KEY
GameKeys.F9KEY
GameKeys.FIVEKEY
GameKeys.FKEY
GameKeys.FOURKEY
GameKeys.GKEY
GameKeys.HKEY
GameKeys.HOMEKEY
GameKeys.IKEY
GameKeys.INSERTKEY
GameKeys.JKEY
GameKeys.KKEY
GameKeys.LEFTALTKEY
GameKeys.LEFTARROWKEY
GameKeys.LEFTBRACKETKEY
GameKeys.LEFTCTRLKEY
GameKeys.LEFTSHIFTKEY
GameKeys.LINEFEEDKEY
GameKeys.LKEY
GameKeys.MINUSKEY
GameKeys.MKEY
GameKeys.NINEKEY
GameKeys.NKEY
GameKeys.OKEY
GameKeys.ONEKEY
GameKeys.PAD0
GameKeys.PAD1
GameKeys.PAD2
GameKeys.PAD3
GameKeys.PAD4
GameKeys.PAD5
GameKeys.PAD6
GameKeys.PAD7
GameKeys.PAD8
GameKeys.PAD9
GameKeys.PADASTERKEY
GameKeys.PADENTER
GameKeys.PADMINUS
GameKeys.PADPERIOD
GameKeys.PADPLUSKEY
GameKeys.PADVIRGULEKEY
GameKeys.PAGEDOWNKEY
GameKeys.PAGEUPKEY
GameKeys.PAUSEKEY
GameKeys.PERIODKEY
GameKeys.PKEY
GameKeys.QKEY
GameKeys.QUOTEKEY
GameKeys.RETKEY
GameKeys.RIGHTALTKEY
GameKeys.RIGHTARROWKEY
GameKeys.RIGHTBRACKETKEY
GameKeys.RIGHTCTRLKEY
GameKeys.RIGHTSHIFTKEY
GameKeys.RKEY
GameKeys.SEMICOLONKEY
GameKeys.SEVENKEY
GameKeys.SIXKEY
GameKeys.SKEY
GameKeys.SLASHKEY
GameKeys.SPACEKEY
GameKeys.TABKEY
GameKeys.THREEKEY
GameKeys.TKEY
GameKeys.TWOKEY
GameKeys.UKEY
GameKeys.UPARROWKEY
GameKeys.VIRGULEKEY
GameKeys.VKEY
GameKeys.WKEY
GameKeys.XKEY
GameKeys.YKEY
GameKeys.ZEROKEY
GameKeys.ZKEY

all the keys. (I think…) I hope this doesn’t violate any posting rules. (too long)… where are the posting rules?


(saluk) #6

Yes, you can use the GameKeys module, so instead of the YOURNUMBER I had, you replace it with whichever GameKeys.* you want. Just remember to add: “import GameKeys” at the top.