Announcement

Collapse
No announcement yet.

Results Not Understood

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

  • Results Not Understood

    I was playing around with some code to turn Windows Magnifier on/off and am seeing something I don't understand.

    The code below works fine on my PC. "Start" turns on the magnifier and "End" turns it off. I can also use WinKey+Add to start the magnifier and WinKey+ESC to close the magnifier. (Add is the plus key on the keyboard numeric keypad)

    Click image for larger version  Name:	pb_2313.jpg Views:	1 Size:	4.5 KB ID:	817896

    But if I run the code on my 2nd PC, the Start/End buttons do not work. Also, if the app is running, the WinKey+Add and WinKey+ESC keys have no effect either. If I close the app, they work!

    I tried it on a 3rd PC as well and I get the same results as on the 2nd PC - but the 2nd and 3rd PCs are not the same and do not have the same keyboards.

    I'm not sure how to explain the results.

    Code:
    'Compilable Example:
    #Compile Exe
    #Dim All
    %Unicode = 1
    #Include "Win32API.inc"
    
    Enum Equates Singular
       IDC_Start = 500
       IDC_End
       IDC_Graphic
    End Enum
    
    Global hDlg As Dword
    
    Function PBMain() As Long
       Dialog New Pixels, 0, "Test",300,300,200,200, %WS_OverlappedWindow To hDlg
       Control Add Button, hDlg, %IDC_Start,"Start", 10,10,60,20
       Control Add Button, hDlg, %IDC_End,"End", 75,10,60,20
       Control Add Graphic, hDlg, %IDC_Graphic, "", 5, 35, 190, 160, %SS_Notify Or %WS_Border
       Graphic Attach hDlg, %IDC_Graphic
       Graphic Color %Black, %rgb_LightYellow
       Graphic Clear
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_Command
             Select Case Cb.Ctl
                Case %IDC_Start : StartMagnifier
                Case %IDC_End   : EndMagnifier
                Case %IDC_Graphic : Beep
             End Select
          Case %WM_ContextMenu
             Dialog End hDlg
    
       End Select
    End Function
    
    Sub StartMagnifier
       keybd_event(%VK_LWIN, &H45, 0, 0)
       keybd_event(%VK_Add, &H45, 0, 0)
       keybd_event(%VK_Add, &H45, %KEYEVENTF_KEYUP, 0)
       keybd_event(%VK_LWIN, &H45, %KEYEVENTF_KEYUP, 0)
    End Sub
    
    Sub EndMagnifier
       keybd_event(%VK_LWIN, &H45, 0, 0)
       keybd_event(%VK_Escape, &H45, 0, 0)
       keybd_event(%VK_Escape, &H45, %KEYEVENTF_KEYUP, 0)
       keybd_event(%VK_LWIN, &H45, %KEYEVENTF_KEYUP, 0)
    End Sub

  • #2
    Works fine on my WIn10 with my Logietch wireless w/ USB dongle.
    Can't test exactly with my laptop built in keyboard since it doesn't have a numeric keypad, but it works as expected with WInkey plus +/= (wherther shifted or not) and -/_ (but not shifted) regardless of whether the application is running or not.

    What OS on each machine?
    What keyboard on each machines?
    What interface USB-WIreless, Bluetooth, USB, PS-2, Serial on each machine?
    Are all of the Settings-Magnifier settings the same on all three machines?

    Comment


    • #3
      How about if you set the hardware scan code param in keybd_event()

      Either to 0 or to mapvirtualkey(%VK_n, 0).. ?

      (Currently the scan code is set to &H45 - a value that is used often on this forum but I couldn't find an explanation)
      Rgds, Dave

      Comment


      • #4
        Originally posted by Dave Biggs View Post
        How about if you set the hardware scan code param in keybd_event()

        Either to 0 or to mapvirtualkey(%VK_n, 0).. ?

        (Currently the scan code is set to &H45 - a value that is used often on this forum but I couldn't find an explanation)
        Scan Code &H45 is normally the NumLock key
        https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html

        but may not be: Follow the link to "sets of codes" in the first paragraph of the above link

        Also note
        https://docs.microsoft.com/en-us/win...er-keybd_event
        Note This function has been superseded. Use SendInput instead.

        Comment


        • #5
          Howdy, Stuart!

          PC1 - WIn11 Home, Microsoft Natural Ergonomic Keyboard, Wired, Magnifier Settings Zoom Level 200%, Zoom Increment 50%, Lens View

          PC2 - Win11 Home, Logitech MK270 Keyboard, Wireless, Same Magnifier Settings

          PC3 - Win11 Home, HP Keyboard that came with the PC, Wireless, Same Magnifier Settings


          The really odd thing is what I mentioned above, which is a problem on machines 2 and 3 only ...

          Also, if the app is running, the WinKey+Add and WinKey+ESC keys have no effect either. If I close the app, they work!
          That the running app can affect whether the system Magnifier shortcut keys work is very strange.


          Howdy, Dave!

          I tried it with scan codes of 0 and get the same result.

          I'm guilty of having used forum code without digging into the arguments of keybd_event. In just a quick read, it seems like the scan codes ought not to be &H45. I'll go read more ...

          Comment


          • #6
            This MSDN example might be the original source of using &H45, where the code was simply copied over by someone without changing the scan codes as needed.

            https://docs.microsoft.com/en-us/win...er-keybd_event

            However, even the MSDN example seems in error, if the comments here are to be believed:

            https://www.codeproject.com/Articles...bd-event-funct

            The codeproject link implies that the make and break scan codes are to be used - NOT the make code in both cases as is shown in the MSDN example.


            There are 2 mysteries - the correct arguments to use AND why a running PBWin app affects the Magnification shortcut keys, I've seen nothing about the interference issue in anything I've read so far.

            To add to the mystery of the PBWin code affecting the Magnification shortcut keys, I created this simple PBWin app and when it runs, it does NOT affect the Magnification shortcut keys on the other 2 PCs.

            Code:
            'Compilable Example:
            #Compiler PBWin 10
            #Compile Exe
            #Dim All
            %Unicode = 1
            #Include "Win32API.inc"
            Global hDlg As Dword
            
            Function PBMain() As Long
               Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %WS_OverlappedWindow To hDlg
               Dialog Show Modal hDlg
            End Function

            Comment


            • #7
              From API docs:

              " keybd_event Function


              The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.

              Windows NT/2000/XP/Vista:This function has been superseded. Use SendInput instead.
              "

              Since Windows Vista this function has been superseded !

              Microsoft has done an excellent job in Windows supporting older API's so as not to break anything, but that said it is possible there will be differences in how Windows handles such API's in later versions.

              Back when one needed to support an OS like XP it made sense to use such API's but Windows 10 has been around a long time now, Windows 11 is the current OS and even Windows 8 will soon not be supported (updates), so it makes little sense to use an API which had been superseded since Windows Vista.

              Chris Boss
              Computer Workshop
              Developer of "EZGUI"
              http://cwsof.com
              http://twitter.com/EZGUIProGuy

              Comment


              • #8
                What if you use...
                Code:
                SUB StartMagnifier
                   keybd_event(%VK_LWIN, MAPVIRTUALKEY(%VK_LWIN, 0), %KEYEVENTF_EXTENDEDKEY, 0)
                   keybd_event(%VK_ADD,  MAPVIRTUALKEY(%VK_ADD, 0), 0, 0)
                   keybd_event(%VK_ADD,  MAPVIRTUALKEY(%VK_ADD, 0), %KEYEVENTF_KEYUP, 0)
                   keybd_event(%VK_LWIN, MAPVIRTUALKEY(%VK_LWIN, 0), %KEYEVENTF_EXTENDEDKEY OR %KEYEVENTF_KEYUP, 0)
                END SUB
                
                SUB EndMagnifier
                   keybd_event(%VK_LWIN,   MAPVIRTUALKEY(%VK_LWIN, 0), %KEYEVENTF_EXTENDEDKEY, 0)
                   keybd_event(%VK_ESCAPE, MAPVIRTUALKEY(%VK_ESCAPE, 0), 0, 0)
                   keybd_event(%VK_ESCAPE, MAPVIRTUALKEY(%VK_ESCAPE, 0), %KEYEVENTF_KEYUP, 0)
                   keybd_event(%VK_LWIN,   MAPVIRTUALKEY(%VK_LWIN, 0), %KEYEVENTF_EXTENDEDKEY OR %KEYEVENTF_KEYUP, 0)
                END SUB

                Comment


                • #9
                  Howdy Pierre!

                  With your suggested code, pressing "Start" does not open the Magnifier on any of the 3 PCs.

                  And, with the app running, the Magnifier will not start on the 2nd and 3d PCs.

                  Comment


                  • #10
                    And, equally strange, if the app is running and I go to Settings, the Magnifier will NOT turn on manually.

                    That is very strange!!!

                    Comment


                    • #11
                      The issue of the Magnifier shortcut keys being disabled is very odd. Even running this small program will disable the Magnifier keyboard shortcuts on the 2nd and 3rd PC of mine, but not on the first.

                      Code:
                      Function PBMain() As Long
                      ? "Test"
                      End Function

                      Comment


                      • #12
                        You got mail, I've sent you some keyboard hook code to check the data sent by the keyboard.

                        Added: This shouldn't be needed but... What if you insert a SLEEP 50 just after keybd_event(%VK_LWIN...
                        Last edited by Pierre Bellisle; 26 Jul 2022, 03:20 PM.

                        Comment

                        Working...
                        X