A device for detecting a user's intention to lock or unlock a motor vehicle opening element, the device being intended to be integrated into a handle (8) or into a frame of the opening element and comprising a voltage source, a printed circuit (3) and at least one sensor for detecting an approach and/or contact of a hand of the user on the handle (8) or the frame, comprising a measuring circuit (1, 2) and at least one detection means (10) that exhibits or induces a variation in a parameter representative of the approach and/or of the contact, the measuring circuit (1, 2), the voltage source and the printed circuit (3) being housed in a housing (7a, 7b), whereas said at least one detection means (10) is housed outside the housing (7a, 7b), wherein the detection means (10) is at least partially in the form of a metallized layer (12) borne by part of an outer contour of a foam block (13) in contact against the housing (7a, 7b) through a bearing face (13a), the face of the foam block (13) opposite the bearing face (13a) bearing the majority of the metallized layer (12).