Microsoft KB Archive/101125: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(2 intermediate revisions by the same user not shown)
Line 64: Line 64:
NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.<br />
NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.<br />
<br />
<br />
There is a workaround for the CAPS LOCK problem. To force input in a field into uppercase, set the control's Format property to &quot;&gt;&quot;. The UCase() function can also be used to force entries in a field to uppercase.<br />
There is a workaround for the CAPS LOCK problem. To force input in a field into uppercase, set the control's Format property to ">". The UCase() function can also be used to force entries in a field to uppercase.<br />
<br />
<br />
Although a SendKeys macro action cannot toggle keys, a Windows API SetKeyboardState() function call can toggle keys. The following example demonstrates how to use the Windows API SetKeyboardState() function:<br />
Although a SendKeys macro action cannot toggle keys, a Windows API SetKeyboardState() function call can toggle keys. The following example demonstrates how to use the Windows API SetKeyboardState() function:<br />
Line 73: Line 73:
<pre class="fixed_text">      Option Explicit
<pre class="fixed_text">      Option Explicit


       Declare Sub GetKeyboardState Lib &quot;User&quot; (ByVal lpKeyState As String)
       Declare Sub GetKeyboardState Lib "User" (ByVal lpKeyState As String)
       Declare Sub SetKeyboardState Lib &quot;User&quot; (ByVal lpKeyState As String)
       Declare Sub SetKeyboardState Lib "User" (ByVal lpKeyState As String)
                         </pre></li>
                         </pre></li>
<li><p>Type the following procedure:<br />
<li><p>Type the following procedure:<br />
Line 80: Line 80:
<pre class="fixed_text">      Function SetKeys ()
<pre class="fixed_text">      Function SetKeys ()
       Dim keys As String
       Dim keys As String
       Const VK_CAPITAL = &amp;H14
       Const VK_CAPITAL = &H14


       keys = Space$(256)
       keys = Space$(256)
Line 86: Line 86:
       GetKeyboardState keys
       GetKeyboardState keys


       If &amp;H1 = (Asc(Mid(keys, VK_CAPITAL + 1, 1)) And &amp;H1) Then
       If &H1 = (Asc(Mid(keys, VK_CAPITAL + 1, 1)) And &H1) Then
           keys = Left(keys, VK_CAPITAL) &amp; Chr(0) &amp; Right(keys, Len(keys) _
           keys = Left(keys, VK_CAPITAL) & Chr(0) & Right(keys, Len(keys) _
             - (VK_CAPITAL + 1))
             - (VK_CAPITAL + 1))
       Else
       Else
           keys = Left(keys, VK_CAPITAL) &amp; Chr(1) &amp; Right(keys, Len(keys) _
           keys = Left(keys, VK_CAPITAL) & Chr(1) & Right(keys, Len(keys) _
             - (VK_CAPITAL + 1))
             - (VK_CAPITAL + 1))
       End If
       End If
Line 130: Line 130:
== REFERENCES ==
== REFERENCES ==


For more information about SendKeys, search for &quot;SendKeys Statement&quot; using the Microsoft Access Help Menu.<br />
For more information about SendKeys, search for "SendKeys Statement" using the Microsoft Access Help Menu.<br />
<br />
<br />
For more information about API functions, search for &quot;API&quot; using the Microsoft Access Help menu.
For more information about API functions, search for "API" using the Microsoft Access Help menu.


</div>
</div>

Latest revision as of 12:24, 21 July 2020

Article ID: 101125

Article Last Modified on 5/6/2003



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition



This article was previously published under Q101125

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

A SendKeys macro action will not work correctly on the toggle keys CAPS LOCK or SCROLL LOCK. You may see the CAPS LOCK or SCROLL LOCK lights flash on the keyboard, but the lights will not remain on and the keys will not be correctly activated after the SendKeys action is completed. Note that SendKeys also will not work correctly with the ALT+PRINT SCREEN key combination.

CAUSE

SendKeys keystrokes are sent to applications at a high level. Microsoft Windows 3.x traps toggle keys and the PRINT SCREEN key at a lower level, keeping them from your application.

RESOLUTION

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

There is a workaround for the CAPS LOCK problem. To force input in a field into uppercase, set the control's Format property to ">". The UCase() function can also be used to force entries in a field to uppercase.

Although a SendKeys macro action cannot toggle keys, a Windows API SetKeyboardState() function call can toggle keys. The following example demonstrates how to use the Windows API SetKeyboardState() function:

  1. Create a module and type the following line in the Declarations section:

          Option Explicit
    
          Declare Sub GetKeyboardState Lib "User" (ByVal lpKeyState As String)
          Declare Sub SetKeyboardState Lib "User" (ByVal lpKeyState As String)
                            
  2. Type the following procedure:

          Function SetKeys ()
          Dim keys As String
          Const VK_CAPITAL = &H14
    
          keys = Space$(256)
    
          GetKeyboardState keys
    
          If &H1 = (Asc(Mid(keys, VK_CAPITAL + 1, 1)) And &H1) Then
              keys = Left(keys, VK_CAPITAL) & Chr(0) & Right(keys, Len(keys) _
                 - (VK_CAPITAL + 1))
          Else
              keys = Left(keys, VK_CAPITAL) & Chr(1) & Right(keys, Len(keys) _
                - (VK_CAPITAL + 1))
          End If
    
          SetKeyboardState keys
    
          End Function
                            
  3. To test this function, type the following line in the Immediate window, and then press ENTER:
     ? SetKeys()
    Note that the CAPSLOCK key will toggle from whatever state it was in previously.


MORE INFORMATION

Steps to Reproduce Behavior

The following SendKeys action will not toggle the CAPS LOCK key to on:

   MacroName       Action
   ----------------------
   Macro1          SendKeys


   Macro1 Actions
   --------------------------
   SendKeys

      Keystrokes:  {CAPSLOCK}
      Wait:        NO
                

REFERENCES

For more information about SendKeys, search for "SendKeys Statement" using the Microsoft Access Help Menu.

For more information about API functions, search for "API" using the Microsoft Access Help menu.


Additional query words: send key num

Keywords: kbprb kbusage KB101125