Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

ToAscii (user32)
 
.
Summary
Summary

C# Signature:

[DllImport("user32.dll")]
static extern int ToAsciiEx(uint uVirtKey, uint uScanCode, byte [] lpKeyState,
   [Out] StringBuilder lpChar, uint uFlags, IntPtr hkl);

Vb.Net Signature:

Public Declare Function ToAsciiEx Lib "user32" (ByVal uVirtKey As UInteger, ByVal uScanCode As UInteger, ByVal lpKeyState As Byte(), <Out()> ByVal lpChar As System.Text.StringBuilder, ByVal uFlags As UInteger, ByVal hkl As IntPtr) As Integer

User-Defined Types:

None.

static extern int ToAscii(uint uVirtKey, uint uScanCode, byte [] lpKeyState,
   byte[] lpwTransKey, uint fuState);
// or
[DllImport("user32.dll")]
static extern int ToAscii(uint uVirtKey, uint uScanCode, byte [] lpKeyState,
   [Out] StringBuilder lpChar, uint uFlags);

VB Signature:

<DllImport("user32")> _
Public Function ToAscii( _
     ByVal uVirtKey As Integer, _
     ByVal uScanCode As Integer, _
     ByVal lpKeyState() As Byte, _
     ByVal lpChar As StringBuilder, _
     ByVal uFlags As Integer)
End Function

Notes:

None.

'or..
Public Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Win32CONST.KeyEvent, ByVal uScanCode As Integer, ByVal lpKeyState() As Byte, ByRef lpChar As Integer, ByVal uFlags As Win32CONST.ToAsciiFlags) As Integer

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

User-Defined Types:

Public Enum ToAsciiFlags As Integer
    MENU_IS_ACTIVE = 1
    MENU_IS_INACTIVE = 0
End Enum

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Documentation
ToAsciiEx on MSDN

Tips & Tricks:

Please add some!

Sample Code:

  <DllImport("User32.dll")> _
  Public Shared Function ToAscii(ByVal uVirtKey As Integer, ByVal uScanCode As Integer, ByVal lpbKeyState As Byte(), ByVal lpChar As Byte(), ByVal uFlags As Integer) As Integer
  End Function

  <DllImport("User32.dll")> _
  Public Shared Function GetKeyboardState(ByVal pbKeyState As Byte()) As Integer
  End Function

  Public Shared Function GetAsciiCharacter(ByVal uVirtKey As Integer, ByVal uScanCode As Integer) As Char
    Dim lpKeyState As Byte() = New Byte(255) {}
    GetKeyboardState(lpKeyState)
    Dim lpChar As Byte() = New Byte(1) {}
    If ToAscii(uVirtKey, uScanCode, lpKeyState, lpChar, 0) = 1 Then
      Return Chr(lpChar(0))
    Else
      Return New Char()
    End If
  End Function

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
ToAscii on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions