I suddenly noticed that the sun roof would always close when I locked the car (E46 2005 M3). Tested with the 2nd key, same thing. This is a "convenient access" function which should only happen with a long push of the lock button on the key. Yet, a long push on the unlock button did not cause the windows and sunroof to open as it should. I read that this may be a coding fault, although how i don't know, and to use the key to lock/unlock. If holding the key in the unlock or lock position causes convenient access to work then not coding but some key issue. So I tried the key in the lock, it barely moved but then became stuck. I have only used the key once, about 18 months ago and it worked fine then. I tried WD40 etc but it was firmly stuck. I then saw some you tube videos on repairing the lock cylinders, and one of these mentioned that the lock tumblers only release with the key in one position, the neutral point between lock and unlock. Any other position locks the key. Fortunately, it is very easy to take the lock cylinder out (see this you tube video https://www.youtube.com/watch?v=f-f-rkejtuY ) and this allows access to either confirm the lock is broken or, in my case, that the switch that the lock operates was a few degrees off vertical. That is the switch was slightly in the lock position. Hence the car thinking I had made a long lock press when I had not, and presumably also why a long unlock was not registered. With the lock cylinder out the key went in and out smoothly. Using a large flat blade screwdriver I could re position the switch, apply some lube, and reassemble. All working fine now. Presumably when I used the key last it jumped slightly and left the lock askew. Just thought I'd share that knowledge.