Announcement

Collapse
No announcement yet.

WinKey

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • WinKey

    I can turn on the Windows Magnifier with code to send WinKey+Plus. Works just like using the keyboard.

    But I cannot get High Contrast to turn on or off. It's shortcut is Left-Shift + Left-Alt + PrtScn

    I've enabled on High Contrast in settings and if I use the keyboard the High Contrast shortcut works just fine. Not sure why the code version does not work.

    I've tried changing the order of the code lines but that didn't seem to matter.

    Code:
    Sub ToggleHighContrast
       '// Press the Left-Shift key
       keybd_event(%VK_LShift, &H45, 0, 0)
       '// Press the Left-Alt key
       keybd_event(%VK_LMenu, &H45, 0, 0)
       '// Press the PrtScn key
       keybd_event(%VK_SnapShot, &H45, 0, 0)
    
       '// Release the PrtScn key
       keybd_event(%VK_SnapShot, &H45, %KEYEVENTF_KEYUP, 0)
       '// Release the Left-Alt key
       keybd_event(%VK_LMenu, &H45, %KEYEVENTF_KEYUP, 0)
       '// Release the Left-Shift key
       keybd_event(%VK_LShift, &H45, %KEYEVENTF_KEYUP, 0)
    End Sub
    
    Sub Magnifier
       '// Press the WinKey
       keybd_event(%VK_LWIN, &H45, 0, 0)
       '// Press the Esc key
       keybd_event(%VK_Escape, &H45, 0, 0)
       '// Release the Esc key
       keybd_event(%VK_Escape, &H45, %KEYEVENTF_KEYUP, 0)
       '// Release the WinKey
       keybd_event(%VK_LWIN, &H45, %KEYEVENTF_KEYUP, 0)
    End Sub

  • #2
    There is a Windows API to turn High Contrast on and off

    '
    Code:
    #COMPILE EXE    'Jose Roca Includes
    #DIM ALL
    #UNIQUE VAR ON
    
    %Unicode = 1
    #INCLUDE "win32api.inc"
    
    FUNCTION PBMAIN () AS LONG
     LOCAL hcOriginal AS HIGHCONTRAST
     LOCAL hcHight AS HIGHCONTRAST
    
    hcOriginal.cbSize = SIZEOF(HIGHCONTRAST)
    SystemParametersInfo(%SPI_GETHIGHCONTRAST, 0, hcOriginal, %SPIF_SENDCHANGE)   ' Get and keep current settings
    
    hcHight=hcOriginal                                                            ' Make a copy
    hcHight.cbSize = SIZEOF(HIGHCONTRAST)
    hcHight.dwFlags = %HCF_HIGHCONTRASTON                                         ' Set Hight contrast flag
    SystemParametersInfo(%SPI_SETHIGHCONTRAST, 0, hcHight, %SPIF_SENDCHANGE)      ' Make Change to Hight Conrast
    
    SLEEP 15000
    SystemParametersInfo(%SPI_SETHIGHCONTRAST, 0, hcOriginal, %SPIF_SENDCHANGE)   ' turn it off
    
    ? "Done"
    END FUNCTION
    '

    Comment


    • #3
      Howdy, Rod!

      Most excellent! Thanks for the information. The great thing about the API is that it does not call up a dialog requiring the user to confirm the choice as does the keyboard shortcut.

      I should go take a look at the list of all SPI values to see what other settings the API provides easy access to.

      It is interesting that my search last night never ran across SPI_SetHightContrast. I found lots of queries from folks wanting to do this, but never saw a hint of this solution.

      I did this, where my Global value hcON is used like this ..


      Code:
      hcOn Xor=1
      SetHighContrast
      
      Sub SetHighContrast
        Local HC As HIGHCONTRAST
        HC.cbSize = SizeOf(HIGHCONTRAST)
        SystemParametersInfo(%SPI_GETHIGHCONTRAST, 0, HC, %SPIF_SENDCHANGE) ' Get and keep current settings
        HC.dwFlags = %HCF_HIGHCONTRASTON * hcON ' Set High contrast flag
        SystemParametersInfo(%SPI_SETHIGHCONTRAST, 0, HC, %SPIF_SENDCHANGE) ' Make Change to Hight Conrast
      End Sub
      ... added ... I went through the SPIxxx list - lots of stuff there but nothing unexpected. I was quite happy that the highcontrast setting was provided.

      Comment

      Working...
      X