Gun locks vary in complexity, and the internal mechanism is typically difficult to understand because the moving parts are obscured by a support plate that is called a bridle. I am using this early banana-shaped flintlock to illustrate and explain the basic internal mechanism of a gun lock because its no-frills mechanism is un-bridled, and therefore unobscured. The following image shows the outwardly facing, external portion of the lock, with the hammer/cock in the fired position. When mounted on a gun and ready for use, the jaws of the hammer/cock would hold a thin piece of flint.
The next photograph shows the very simple internal mechanism of this particular lock, which was designed for use with a simple L-shaped trigger (see below), rather than a set trigger arrangement. In operation, the falling (i.e., rotating) motion of the hammer/cock causes an impact that ignites the gunpowder within the gun barrel. With a flintlock, the impact creates a flint-on-steel spark that ignites the gunpowder. With a percussion lock, the impact detonates a percussion cap, which ignites the gunpowder.
The tumbler has a cylindrical axle that projects through, and is rotationally guided by, a a closely-fitting cylindrical hole in the lock plate. The hammer/cock is closely fitted to, and threadedly retained to, a flattened end-portion of the axle, and therefore rotates in concert with the tumbler. The mainspring applies a heavy downward force to a mating surface of the tumbler. The nose of the lightly spring-loaded sear prevents rotation of the tumbler and the hammer/cock by engaging one of the two notches on the tumbler. The deep notch/slot is the half-cock notch, and the shelf-like notch is the full-cock notch. When the hammer is pulled back far enough to allow the nose of the sear to engage the full-cock notch, the gun is ready to fire. The associated rotation of the tumbler further compresses the mainspring, storing additional potential energy. When the trigger (not shown) is pulled, it contacts and and lifts the sear arm, overcoming the downwardly acting force of the sear spring and rotating the nose of the sear out of engagement with the full-cock notch of the tumbler. Since the hammer is no longer propped in the full-cock position by the sear, the force of the mainspring causes the hammer to fall (i.e., rotate rapidly with the tumbler) to create the impact (referenced above) that fires the gun. As the tumbler rotates, the continuing force of the trigger acting on the sear arm prevents the nose of the sear from from inadvertently engaging and damaging the half-cock notch. (Incidentally, at the engineering firm where I worked for 38 years, we jokingly referred to slotted notches as "snotches!")
When the hammer/cock and tumbler are intentionally rotated to allow the nose of the sear to engage the half-cock notch, pulling the trigger should not fire the gun because the nose of the sear is trapped by the shape of the notch.
The following drawing shows the type of trigger used with the lock pictured above. Pulling the trigger lifts the sear arm, firing the gun.
The next photo provides a glimpse of the more complicated internal mechanism of a percussion lock that is configured for use with a set trigger arrangement. The tumbler and part of the sear are obscured by the bridle plate. The tumbler has a small cylindrical axle that passes through and engages a closely fitting hole in the bridle plate. This engagement provides a second bearing surface for the tumbler, for better stability/guidance. Although you can't see it because of the bridle plate, the tumbler incorporates an additional component called a "fly" that prevents the sear from engaging and damaging the half-cock notch when the gun is fired with a set trigger. Since this web page is about basics, you will have to go elsewhere to learn about flies and various other lock refinements.
For more photos of this lock and the rifle it goes with, click here.