A system for detecting the position of at least one moveable element (141, 161, 170, 470, 570) of a window or door assembly, the window or door assembly having a leaf (12, 112) and a frame (11, 111), the leaf being moveable relative to the frame between a closed position and an open position, the window or door assembly having a latch mechanism to allow opening and closing of the leaf, said moveable element moving relative to a reference structure during operation of the latch mechanism, the moveable element being mounted to the leaf such that it moves with the leaf when the leaf is moved between its open and its closed positions, the system comprising: the at least one moveable element (141, 161, 170, 470, 570); at least one magnetic field generator (31, 113, 161, 172, 472, 572); at least one sensor (53, 153) for sensing a magnetic field, the at least one sensor being configured such that the magnetic field sensed changes as the at least one moveable element moves, one of said magnetic field generator and sensor being mounted to the moveable element and the other being mounted in use to the reference structure that the moveable element is moveable relative to, the at least one sensor comprising a three axis magnetometer (53, 153) that is able to detect the position of the corresponding magnetic field generator in three coordinate axes; and the system further comprising processor means configured to receive output signals associated with the sensed magnetic field from the sensor and to determine the position of the at least one moveable element; wherein the system is configured to operate in a calibration mode and a normal mode, wherein in the calibration mode the system is configured to register at least an output value from the at least one sensor when the at least one moveable element is at a first predetermined position as a corresponding first reference value and wherein in the normal mode the processor means is configured to use at least the first reference value in determining the position of the at least one moveable element. the at least one moveable element (141, 161, 170, 470, 570); at least one magnetic field generator (31, 113, 161, 172, 472, 572); at least one sensor (53, 153) for sensing a magnetic field, the at least one sensor being configured such that the magnetic field sensed changes as the at least one moveable element moves, one of said magnetic field generator and sensor being mounted to the moveable element and the other being mounted in use to the reference structure that the moveable element is moveable relative to, the at least one sensor comprising a three axis magnetometer (53, 153) that is able to detect the position of the corresponding magnetic field generator in three coordinate axes; and the system further comprising processor means configured to receive output signals associated with the sensed magnetic field from the sensor and to determine the position of the at least one moveable element; wherein the system is configured to operate in a calibration mode and a normal mode, wherein in the calibration mode the system is configured to register at least an output value from the at least one sensor when the at least one moveable element is at a first predetermined position as a corresponding first reference value and wherein in the normal mode the processor means is configured to use at least the first reference value in determining the position of the at least one moveable element.