It's certainly a tricky question—the Chicago Manual of Style, for example, has no general guidance that I could find as to the appropriate format when following the American convention. It does offer an exception in section 7.75, which according to the section title, applies only to things that are to be literally typed, but I believe your example is close enough to apply the same rule.
If quotation marks must be used, any punctuation that is not part of the quoted expression should appear outside the quotation marks (as in the second example; see also 6.9)
Furthermore, Wikipedia does have this to offer:
Many American style guides explicitly permit periods and commas outside the quotation marks when the presence of the punctuation mark inside the quotation marks will lead to ambiguity, such as when describing keyboard input:
To use a long dash on Wikipedia, type in “—”.
Since, as you say, including the period inside the comma would be confusing, you should probably place the period outside the quotation marks.
Personally, I'd recommend using British style (aka logical punctuation), since by virtue of attempting to be logical, it ends up much easier than American style.