Search notes:

Examples for Visual Basic for Application accessing the Windows API: VkKeyScanEx

VkKeyScanEx can be used to determine which keys a user has to type on his keyboard so that it results in a desired character. This is especially useful for characters that are obtained by a combination of the shift and another key.
This example needs the VBA declarations of the Windows API which can be found here.
option explicit

dim keyboardLayout as long

sub main() ' {


    keyboardLayout = GetKeyboardLayout(0)

    showCharInfo "c"
    showCharInfo "C"
    showCharInfo "="
    showCharInfo "+"
'   showCharInfo chr(1)

end sub ' }

sub showCharInfo(char as string) ' {

    dim keyScan as integer
    dim shift   as boolean
    dim ctrl    as boolean
    dim vkKey   as integer

    keyScan = VkKeyScanEx(asc(char), keyboardLayout)

    shift = keyScan and &h100
    ctrl  = keyScan and &h200
    vkKey = keyScan and &h0ff

    debug.print char & ": " + iif(shift, "shift ", "      ") + iif(ctrl, "ctrl ", "     ") & chr(vkKey) & " " & vkKey


end sub ' }
Github repository WinAPI-4-VBA, path: /examples/VkKeyScanEx.bas

See also

SendInput
Other examples

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759390505, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/Win-API/examples/VkKeyScanEx(80): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78