Preheat oven to 350 degrees F. Grease a 9x13 casserole dish with butter.
Heat butter in a large rimmed skillet. Add diced onions and cook for 1 to 2 minutes. Add diced ham and cook for 3 to 4 minutes. Remove from heat and set aside.
Combine milk and cream in a microwave-safe bowl and microwave for a minute until it is no longer cold. Whisk in flour and black pepper. Set aside.
Mix both shredded cheeses together. Set aside.
Using a mandolin or slicer, slice potatoes into ⅛-inch slices (very thin.) Layer ⅓ of the potato slices in the buttered casserole dish. Next, sprinkle on ⅓ of the ham/onion mixture, then ⅓ of the cheese, then pour on ⅓ of the cream/milk mixture. The potatoes can be sliced by hand, but make sure they are thin as it will impact cooking time.
Repeat this layering process twice more and end with a sprinkling of cheese and a pouring on of the rest of the cream mixture. Cover dish with foil and bake for 50 minutes. Remove the foil and bake for an additional 20 minutes until the potatoes are tender. Allow the casserole to sit on the counter to rest for about 5 minutes before serving.