From what I feel, 74hct165 and 74hct404 could be removed the whole thing could be done in software. What's your "clock" signal looks like?

Timer interrupt to scan your keyboard and refresh your display... main loop to process your clock.