To understand this answer to your question, we need to first look at how keyboard input works.
Microsoft have a whole section on this:
When a key is pressed on a keyboard, a scan code is generated. Scan codes are device-dependent.
Next:
The keyboard device driver receives scan codes from the keyboard
and turns them into virtual keys:
a device-independent value defined by the system that identifies the purpose of a key.
A virtual key represents the keys on a keyboard, and not what characters they can represent. So, for example 3 is a virtual key, but it's shifted value (£ in my case), isn't, and depends on the keyboard in use.
These are stored in the device-dependent KeyboardLayout. The basic function calls such as MapVirualKey use a default keyboard layout (i.e. the one you are using now). If you want to use different layouts, you can get a list by calling:
GetKeyboardLayoutList
So a virtual key and any modifiers are sent to the keyboard layout and this returns the appropriate character, which is then rendered to the screen, etc...
So your question becomes, 'How can we find the Unicode/ASCII value of myKey + shift?'. There isn't any particularly easy answer, for example on my computer 'shift 3 (£)' with ASCII value 163, but 'shift 4 ($)' has an ASCII value of 36!
These examples use Excel, not Powerpoint.
Let's look at MapVirtualKey` first. I have not used a general keyboard layout.
In a module, add the following declaration:
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mapvirtualkeya
Public Declare PtrSafe Function MapVirtualKeyA Lib "user32" ( _
ByVal uCode As Long, _
ByVal uMapType As Long) As Integer
and add the following subroutine to Button1:
Sub Button1_Click()
Cells.Clear
' MapVirtualKeyA
Cells(1, 1) = "MapVirtualKeyA"
Cells(1, 1).Font.Bold = 1
char = "3"
Cells(2, 1) = "char: " & char
Cells(2, 2) = MapVirtualKeyA(Asc(char), 2)
Cells(2, 3) = Chr(MapVirtualKeyA(Asc(char), 2))
char = "£"
Cells(3, 1) = "char: " & char
Cells(3, 2) = MapVirtualKeyA(Asc(char), 2)
Cells(3, 3) = Chr(MapVirtualKeyA(Asc(char), 2)) ' doesn't exist
The first call works fine, the second doesn't recognise £ as a virtual key (it isn't), and so returns 0.
So this isn't much use at determining what 'shift 3' should return.
We can retrieve the 'shift' state from £, by using the VkKeyScan API function.
Declare the function in a module:
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-vkkeyscana
Public Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" ( _
ByVal cChar As Byte) As Integer
and add this code to a button:
'VkKeyScan
Cells(5, 1) = "VkKeyScan"
Cells(5, 1).Font.Bold = 1
char = "3"
keyScan = VkKeyScan(Asc(char))
shift = keyScan And &H100
ctrl = keyScan And &H200
vkKey = keyScan And &HFF
Cells(6, 1) = "char: " & char
Cells(6, 2) = "shift: " & shift
Cells(6, 3) = "ctrl: " & ctrl
Cells(6, 4) = keyScan
Cells(6, 5) = ChrW(keyScan)
Cells(6, 6) = vkKey
Cells(6, 7) = Chr(vkKey)
char = "£"
keyScan = VkKeyScan(Asc(char))
shift = keyScan And &H100
ctrl = keyScan And &H200
vkKey = keyScan And &HFF
Cells(7, 1) = "char: " & char
Cells(7, 2) = "shift: " & shift
Cells(7, 3) = "ctrl: " & ctrl
Cells(7, 4) = keyScan
Cells(7, 5) = ChrW(keyScan) ' wrong character
Cells(7, 6) = vkKey
Cells(7, 7) = Chr(vkKey)
This is more informative, but still doesn't give us the answer.
There are two solutions from here, both are pretty much the same:
SendInput is the official Win32API way to do things, but involves fairly long code, and is neatly wrapped up by the VBA SendKeys function.
SendKeys sends text output to the currently active cursor.
Cells(10, 1).Select
SendKeys ("3+3~")
While Cells(10, 1) = ""
DoEvents
Wend
Cells(10, 2) = Asc(Mid(Cells(10, 1), 1, 1))
Cells(10, 3) = Asc(Mid(Cells(10, 1), 2, 1))
End Sub
Cells(10, 1).Select places the cursor where we want it.
+ is used to simulate 'shift', and ~ simulates 'enter'.
Wait while the processor catches up.., and we have the ASCII value for '£'!