Announcement

Collapse
No announcement yet.

Arrow keys

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

  • Arrow keys

    I have this in a subclass procedure:
    Code:
    case %WM_KEYDOWN
                control get loc ghForm,gControl to x,y
                control get size ghForm,gControl to w,h
                select case wparam
                    case %VK_PGUP
                        decr y
                        control set loc ghForm,gControl,x,y
                    case %VK_PGDN
                        incr y
                        control set loc ghForm,gControl,x,y
                    case %VK_HOME
                        decr x
                        control set loc ghForm,gControl,x,y
                    case %VK_END
                        incr x
                        control set loc ghForm,gControl,x,y
                    case %VK_F8
                        decr w
                        control set size ghForm,gControl,w,h
                    case %VK_F9
                        incr w
                        control set size ghForm,gControl,w,h
                    case %VK_F11
                        incr h
                        control set size ghForm,gControl,w,h
                    case %VK_F12
                        decr h
                        control set size ghForm,gControl,w,h
    This does exactly what I want it to do; however, the keys are rather "non-standard". I would rather use the shift+arrow keys and ctrl+arrow keys. So the subclassing and using %WM_KEYDOWN messages I have got the "hang of", it is just the keys I want to use don't work because I suspect they;like the F10 key, are reserved by default for other use. If I create say two buttons on a form, the arrow keys automatically switch back and forth between the buttons. I looked in the win32api.hlp file for a way to "remap"(for lack of a better term)these keys but didn't find anything. If ya' could give me some insight on the shift,ctrl and arrow keys and a way to define them for specific tasks I would appreciate it.

    Thanks,
    Adam

  • #2
    Adam --
    didn't test, but it seems to me, that GeyKeyboardState in this moment should return correct status of all keys (before pressing new key)

    ------------------

    Comment


    • #3
      I have done some more playing around and discovered I can intercept the %WM_SYSKEYDOWN message and process the alt+arrow keys no problem but still can't process the aroow keys with %WM_KEYDOWN in the subclass procedure. Hmmmm, interesting - I will continue to experiment. I will also experiment with GetKeyboardstate but it seems to me that is not my answer. The arrow keys seem to be virtual keys just like HOME,END, DELETE and the function keys and I can processs them with no problem. I wonder if there is another message for the arrow keys where I dont' have to use the alt key.
      Hmmmmm,....

      Regards,
      Adam

      ------------------

      Comment


      • #4
        Adam,
        This works for me:
        {code}
        SELECT CASE wMsg&
        CASE %WM_KEYDOWN
        KK&=GETKEYSTATE(%VK_SHIFT)
        IF KK&=-127 OR KK&=-128 THEN
        IF wParam&=%VK_TAB THEN 'Tab to the left
        ...
        ...
        ...
        END IF
        END IF

        SELECT CASE wParam&
        CASE %VK_UP 'Up-arrow key
        ...
        ...
        ...
        CASE %VK_DOWN 'Down-arrow key
        ...
        ...
        ...
        CASE %VK_TAB 'Tab to the right
        ...
        ...
        ...
        END SELECT
        CASE %WM_KEYUP
        ...
        ...
        ...
        CASE %WM_CHAR
        ...
        ...
        ...

        END SELECT
        [/code]

        Edmund

        ------------------

        Comment


        • #5
          Fellows, you seem to be having more sucess at doing what I want
          to do. Right now I'm using a MODELESS dialog with

          GetMessage(tMsg,%NULL,0,0)

          to get keyboard input. I went that way because the keyboard
          messages did not appear to be avaialble using a MODAL dialog
          with CallBack functions.

          Apparently there is a way to get keyboard message inside a
          CB function -- subclassing?

          Could someone provide a simple DDT skeleton just to be able
          to get keyboard messages (right now I'm interested in only
          A/N and the ENTER key. I'll process them and then REMOVE them
          from Windows purview. All others would be passed thru to
          Windows. No need for fancy Fn or cursor controls (yet).

          I'd appreciate any suggestions.

          Aloha,



          ------------------

          Comment


          • #6
            Adam --
            Try this (at least on my PC - Win2000 - works) - see code bellow


            [This message has been edited by Semen Matusovski (edited February 29, 2000).]

            Comment


            • #7
              Hey y'all,
              Thanks for the replies. Since my last post I played around with the code and discovered that if I do this:
              Code:
              case %WM_KEYUP
                          keystate = GetAsyncKeyState(%VK_CONTROL)
                          control get loc ghForm,gControl to x,y
                          control get size ghForm,gControl to w,h
                          select case wparam
                              case %VK_UP
                                  if keystate then
                                      decr h  
                                      control set size ghForm,gControl,w,h
                                  else
                                      decr y
                                      control set loc ghForm,gControl,x,y
                                  end if
                              case %VK_DOWN
                                  if keystate then
                                      incr h
                                      control set size ghForm,gControl,w,h
                                  else
                                      incr y
                                      control set loc ghForm,gControl,x,y
                                  end if
                              case %VK_LEFT
                                  if keystate then
                                      decr w
                                      control set size ghForm,gControl,w,h
                                  else
                                      decr x
                                      control set loc ghForm,gControl,x,y
                                  end if
                              case %VK_RIGHT
                                  if keystate then
                                      incr w
                                      control set size ghForm,gControl,w,h
                                  else
                                      incr x
                                      control set loc ghForm,gControl,x,y
                                  end if
              As you can see Edmund, I basically came up with the same thing that you use. This code does what I want except for one minor detail - since the repeat count for the %WM_KEYUP is always one(for obvious reasons),I have to keep plunking on the arrow keys to move or resize the controls I create. I can move the controls with just the arrow keys and use CTRL+arrow keys to resize the controls. The continous plunking is not a major issue although it would be nice to do repeating(Life will continue though if I can't). I would be curious as to why when I simply switch the message from %WM_KEUP to %WM_KEYDOWN, the arrow keys stop being processed. Hmmmmmmm, I guess I will have to do some more experimenting on this. I will check out you code Semen and see if that will allow me to use %WM_KEYDOWN and the arrow keys. Joe, try Semen's code that he posted in this thread and see if that works, also there is an example of subclassing that was posted by Lance sometime ago, let me go back and get the url for it and I will post it again for ya'.

              Thanks guys,
              Adam

              ------------------

              Comment


              • #8
                here's the url joe,
                . hope this helps as well as semens' example.

                regards,
                adam


                ------------------

                Comment


                • #9
                  Hmmmmm, the arrow keys are still acting like tab keys even when I use %WM_KEYUP,if I create more than one control on a form,pressing the arrow keys tabs between the controls. I thought that was what the TAB key was for. Interesting...

                  Regards,
                  Adam


                  ------------------

                  Comment


                  • #10
                    Semen: Your code works great! I've been trying to find such code for a good couple weeks now, and it is a real reliefe to see PowerBasic trap the keystrokes in a dialog. Thank you SO much for the help!

                    I have one question. I want to capture control+letter keystrokes in my dialog, but I don't have a clue how to go about it. I know the message is sent to my While loop in the form of a %WM_Char message, but there is no %VK_A definition to use in conjunction with your control checking IF statement. I tried selecting a case for %WM_CHAR and using a CASE 97 statement followed by the If statement to check for control, but it refuses to recognise that anything was pressed. Any suggestions?

                    ------------------

                    Comment


                    • #11
                      Oh hey all,
                      I got my arrow key processing working in response to a %WM_KEYDOWN message. It turned out it was due to a modal\modeleless issue in one of the other windows that is showing simultaneouly with the window I am doing the arrow key processing. Problem corrected, works just great now.

                      Regards,
                      Adam

                      ------------------

                      Comment


                      • #12
                        Danny --
                        try this
                        Code:
                        #Compile Exe
                        #Register None
                        DefLng A-Z
                        #Include "Win32Api.Inc"
                        Global Stop&
                        
                        CallBack Function hDlg_CB
                           Select Case CbMsg
                              Case %WM_DESTROY: Stop = 1
                           End Select
                        End Function
                        
                        Function PbMain()
                           Local Msg  As tagMsg
                           Dialog New 0 ,"SubClass ?", 0, 0, 200, 100, %DS_CENTER Or %WS_SYSMENU To hDlg
                           Control Add Label,  hDlg, 101, "Label", 10, 5, 30, 12
                           Control Add TextBox,  hDlg, 201, "Edit control-1", 10, 25, 170, 12
                           Control Add Button,  hDlg, 102, "&Button", 40, 5, 130, 12
                           Control Add TextBox,  hDlg, 202, "Edit control-2", 10, 45, 170, 12
                           Control Add ComboBox, hDlg, 301,, 10, 65, 170, 100, %CBS_DROPDOWNLIST Or %WS_TABSTOP
                           ComboBox Add hDlg, 301, "Combo box": ComboBox Select hDlg, 301, 1
                           Dialog Show Modeless hDlg Call hDlg_CB
                           While GetMessage(Msg, %NULL, 0, 0)
                              Local Title$: Title$ = ""
                              Select Case Msg.message
                                 Case %WM_SYSKEYDOWN
                                    Select Case Msg.wParam
                                       Case %VK_LEFT : Title$ = "ALT + LEFT ARROW"
                                       Case %VK_RIGHT: Title$ = "ALT + RIGHT ARROW"
                                       Case %VK_DOWN : Title$ = "ALT + ARROW DOWN"
                                       Case %VK_UP   : Title$ = "ALT + ARROW UP"
                                    End Select
                                 Case %WM_KEYDOWN
                                    If IsTrue(LoWrd(GetKeyState(%VK_CONTROL)) And &H8000) Then
                                       Select Case Msg.wParam
                                          Case %VK_LEFT : Title$ = "CONTROL + LEFT ARROW"
                                          Case %VK_RIGHT: Title$ = "CONTROL + RIGHT ARROW"
                                          Case %VK_DOWN : Title$ = "CONTROL + ARROW DOWN"
                                          Case %VK_UP   : Title$ = "CONTROL + ARROW UP"
                                          Case 65 To 90 : Title$ = "CONTROL + " + Chr$(Msg.wParam)
                                       End Select
                                    ElseIf IsTrue(LoWrd(GetKeyState(%VK_SHIFT)) And &H8000) Then
                                       Select Case Msg.wParam
                                          Case %VK_LEFT : Title$ = "SHIFT + LEFT ARROW"
                                          Case %VK_RIGHT: Title$ = "SHIFT + RIGHT ARROW"
                                          Case %VK_DOWN : Title$ = "SHIFT + ARROW DOWN"
                                          Case %VK_UP   : Title$ = "SHIFT + ARROW UP"
                                       End Select
                                    End If
                              End Select
                              If Title$ <> "" Then
                                 If Msg.hWnd = GetDlgItem(hDlg, 201) Then Title$ = Title$ + " in TextBox-1" Else _
                                 If Msg.hWnd = GetDlgItem(hDlg, 202) Then Title$ = Title$ + " in TextBox-2" Else _
                                 If Msg.hWnd = GetDlgItem(hDlg, 301) Then Title$ = Title$ + " in Combo Box"
                                 SetWindowText hDlg, ByVal StrPtr(Title$)
                              ElseIf IsDialogMessage(hDlg, Msg) = %FALSE Then  ' Don't touch Tab
                                 TranslateMessage Msg
                                 DispatchMessage Msg
                              End If
                              If Stop <> 0 Then Exit Do
                           Loop
                           MsgBox "Ok"
                        End Function
                        %VK_A to %VK_Z are not included, because they are equal ASC' codes
                        %VK_A = ASC("A") = 65
                        ...
                        %VK_Z = ASC("Z") = 90

                        [This message has been edited by Semen Matusovski (edited February 29, 2000).]

                        Comment


                        • #13
                          Semen: You have a very impressive understanding of how the messages in a dialog are processed. I'm impressed! Thanks so much for your quick reply; the code works great and now ctrl+d pops up a date box anywhere in my application-even in the dialog!

                          Again, thanks for all the help.--Danny.

                          ------------------

                          Comment


                          • #14
                            Just to be clear: Semen's code is using an (as yet) undocumented method of processing the message queue for the DDT engine - R&D have not told me if this is a 100% safe technique. Use this technique "at you own risk".



                            ------------------
                            Lance
                            PowerBASIC Support
                            mailto:[email protected][email protected]</A>
                            Lance
                            mailto:[email protected]

                            Comment


                            • #15
                              Thanks Lance, I'll keep that in mind. Sorry to be such a bother everyone, I'm trying to make F10 a local toggle in one of my dialogs, and capture the print screen key to make it actually do something useful. Thus, I've used the Case %VK_F10 and Case %VK_Print statements Under the Select Case Msg.Message, Case %WM_KeyDown, Select Case Msg.wParam statements in my message loop to capture these keys, but the case never happens. What am I doing wrong this time?

                              Thanks so much for your help.

                              Danny.

                              ------------------

                              Comment


                              • #16
                                Danny --
                                I guess that Print Screen not works, because Windows reserves this key for copying image of Desktop to clipboard and doesn't transfer this message to apps.
                                Better to forget about this key.

                                About F10. - On my PC - no problems, similar like with others F1..F12 (%WM_KEYDOWN).

                                On your PC could be resident programs (screen savers, keyboard drivers ...), which reserve this key (try to remember additional programs).

                                To say true, I know one, enoough simple way to found Print Screen pressing (SetWindowHookEx), but I don't like this technique.
                                Also this code doesn't prevent copying of desktop's image to clipboard.
                                For example:
                                Code:
                                   #Compile Exe
                                   #Register None
                                   #Dim All
                                   #Include "win32Api.inc"
                                   Global ghKbrdHook As Long
                                   Global lpfnKbrdHook As Long
                                   Global hDlg As Long
                                   
                                   Function KeyboardHook(ByVal iCode As Integer, ByVal wParam As Long, ByVal lParam As Long) As Long
                                      If iCode = %HC_ACTION And wParam = &H2C Then
                                         SetWindowText hDlg, "Print Screen pressed " + Time$
                                         ' Function = 1: Exit Function
                                      End If
                                      Function = CallNextHookEx(ghKbrdHook, iCode, wParam, lParam)
                                   End Function
                                   
                                   CallBack Function Cb
                                      Select Case CbMsg
                                         Case %WM_INITDIALOG
                                            ghKbrdHook = SetWindowsHookEx(%WH_KEYBOARD, CodePtr(KeyboardHook), _
                                               0, GetCurrentThreadId)
                                         Case %WM_DESTROY
                                            UnhookWindowsHookEx ghKbrdHook
                                      End Select
                                   End Function
                                   
                                   Function PbMain
                                      Dialog New 0,"Test",,,200,100, %ws_sysmenu To hdlg
                                      Control Add TextBox, hdlg,100, "", 10, 10,180, 12, %WS_BORDER
                                      Dialog Show Modal hdlg Call Cb
                                   End Function

                                [This message has been edited by Semen Matusovski (edited April 03, 2000).]

                                Comment

                                Working...
                                X