Vafa-Witten theory is a twisted N = 4 supersymmetric gauge theory whose partition functions are the generating functions of the Euler number of instanton moduli spaces. In this paper, we recall quantum gauge theory with discrete electric and magnetic fluxes and review the main results of Vafa-Witten theory when the gauge group is simply laced. Based on the transformations of theta functions and their appearance in the blow-up formulae, we propose explicit transformations of the partition functions under the Hecke group when the gauge group is non-simply laced. We provide various evidences and consistency checks. development in both topology and S-duality. Recently, there has been much interest in the third twist [24] for its relation to the geometric Langlands programme [20,9,8,34].In this paper, We revisit the Vafa-Witten theory with an emphasis on the roles of Langlands duals. While much progress has been made when the gauge group is simply laced, both in physics [25,22,16,17] and in mathematics [21,38,39,23,13], there has been almost no attempt in studying the Vafa-Witten theory in the non-simply laced case (see however [19]). The latter differs from the simply laced case in several crucial ways. First, as the gauge group is distinct from its dual, we need to consider simultaneously two sets of discrete fluxes and hence two sets of partition functions. Second, the Z 2 -duality of electricity and magnetism is not part of the modular group, but the Hecke group [10, 6, 1], which has different relations on the generators. Based on the transformations of theta functions and their appearance in the blow-up formulae, we propose explicit transformations of the partition functions with various discrete fluxes under the Hecke group. This would be the counterpart, when the gauge group is non-simply laced, of the sharpened S-duality conjecture of Vafa and Witten [31].The organisation of the paper is as follows. In Section 2, we review 't Hooft's discrete electric and magnetic fluxes [15] and their role in canonical and path integral quantisation. Given an arbitrary simple gauge group, we choose a subset of permitted discrete fluxes so that under S-duality, the discrete electric and magnetic fluxes are interchanged. In Section 3, we consider Vafa-Witten theory for simply laced gauge groups. The sharpened S-duality conjecture [31] specifies how the partition functions with various discrete fluxes transform under the modular group. From this and the above selection of discrete fluxes for arbitrary gauge groups, we deduce the usual Z 2 -duality which exchanges the gauge group and its Langlands dual. To compare with the non-simply laced case, we summarise the relevant mathematical results, especially the blow-up formulae [38,31,23,19], in which the universal factors contain theta functions constructed from the coroot lattice [19] and the Dedekind eta function. In Section 4, we study Vafa-Witten theory for non-simply laced gauge groups. There are two sets of partition functions which transform under the Hecke group. To find the...