Inconsistent results..

Started by Exploration Gaming , May 30, 2013, 05:32:55 PM

Previous topic - Next topic

Exploration Gaming

I am using PB9 and FireFly 3.

I am getting very un-predictable results when I compile my application. I've always likes FF, but it has never been as "reliable" as I would like in an IDE..

My concerns are..

1) Delete Key doesn't fire and event.
2) Control +Z, X, C, V didn't work so I added the following event to the KEYUP/ KEYDOWN



'--------------------------------------------------------------------------------
FUNCTION FRMSNIP_TEXT1_WM_KEYDOWN ( _
                                  ControlIndex  AS LONG,  _  ' index in Control Array
                                  hWndForm      AS DWORD, _  ' handle of Form
                                  hWndControl   AS DWORD, _  ' handle in Control
                                  nVirtKey      AS LONG,  _  ' virtual key code
                                  lKeyData      AS LONG   _  ' key data
                                  ) AS LONG

    SELECT CASE nVirtKey
        CASE %VK_CONTROL
            blCtrlKey = %True
           
        CASE %VK_C
            IF blCtrlKey THEN
                FF_TEXTBOX_COPY( hWndControl )
            END IF
        CASE %VK_X
            IF blCtrlKey THEN
                FF_TEXTBOX_CUT( hWndControl )
            END IF
        CASE %VK_V
            IF blCtrlKey THEN
                FF_TEXTBOX_PASTE( hWndControl )
            END IF
    END SELECT
END FUNCTION


'--------------------------------------------------------------------------------
FUNCTION FRMSNIP_TEXT1_WM_KEYUP ( _
                                ControlIndex  AS LONG,  _  ' index in Control Array
                                hWndForm      AS DWORD, _  ' handle of Form
                                hWndControl   AS DWORD, _  ' handle in Control
                                nVirtKey      AS LONG,  _  ' virtual key code
                                lKeyData      AS LONG   _  ' key data
                                ) AS LONG

    SELECT CASE nVirtKey
        CASE %VK_CONTROL
            blCtrlKey = %False
    END SELECT
END FUNCTION



After the code was added it works on the first compile and now the event only fires when I hold the SHIFT key... Control + Shift + Z,X,C,V.. ??!?!?! (Why would it now require shift to be held)

Basically, my concern is that these problems are totally random, and follow no real logic to the code I have added..  I also noticed that some events don't fire as regularly as DDT forms.

Any help would be appreciated on trapping key events reliably.

Thanks in advance.
Explorations RPG System
"RPG Makers come & Go, But Explorations is Forever!"
http://www.explore-rpg.com

Paul Squires

#1
Quote from: Exploration Gaming  on May 30, 2013, 05:32:55 PM
I am getting very un-predictable results when I compile my application. I've always likes FF, but it has never been as "reliable" as I would like in an IDE..

FF is "Reliable" because it gives the programmer the exact information coming from the Windows message pump. What is not reliable is how the programmer uses that data.  :P

You are testing for CTRL and/or SHIFT incorrectly. You shouldn't test for CONTROL and set a global flag. You need to use GetAsyncKeyState during the KeyDown message.

I will put together some test code and post it for you shortly....

Paul Squires
PlanetSquires Software

Paul Squires

This should get you started:


'--------------------------------------------------------------------------------
Function FORM1_TEXT1_WM_KEYDOWN ( _
                              ControlIndex  As Long,  _  ' index in Control Array
                              hWndForm      As Dword, _  ' handle of Form
                              hWndControl   As Dword, _  ' handle in Control
                              nVirtKey      As Long,  _  ' virtual key code
                              lKeyData      As Long   _  ' key data
                              ) As Long

   Local st As String
   

   Select Case nVirtKey
      Case %VK_DELETE 
         If GetAsyncKeyState(%VK_CONTROL) And &H8000 Then st = st & " Ctrl "
         If GetAsyncKeyState(%VK_SHIFT) And &H8000 Then st = st & " Shift "
         st = st & " DEL"
         
      Case %VK_C
         If GetAsyncKeyState(%VK_CONTROL) And &H8000 Then st = st & " Ctrl "
         If GetAsyncKeyState(%VK_SHIFT) And &H8000 Then st = st & " Shift "
         st = st & " C"
     
      Case %VK_V
         If GetAsyncKeyState(%VK_CONTROL) And &H8000 Then st = st & " Ctrl "
         If GetAsyncKeyState(%VK_SHIFT) And &H8000 Then st = st & " Shift "
         st = st & " V"

      Case %VK_X
         If GetAsyncKeyState(%VK_CONTROL) And &H8000 Then st = st & " Ctrl "
         If GetAsyncKeyState(%VK_SHIFT) And &H8000 Then st = st & " Shift "
         st = st & " X"
         
   End Select
   
   FF_Control_SetText hWndForm, st

End Function

Paul Squires
PlanetSquires Software

Exploration Gaming

#3
I can check the state..no problem.. My comment about "reliable" is because its not firing the event.

For example :

1) The delete key simply is ignored, it never works.
2) The VK_X even never fires.. I simply put a msgbox on the event, and it only triggered the event when the shift key was held.


FYI : When using this TEXTBOX_COPY, CUT, PASTE function.. I have also seen duplicate data pushed from the events. (Copy "Hello", Paste "HelloHello") Its as if Firefly isn't managing the Dialog to Control IDS properly, and it firing twice because 2 events (on separate dialogs, but identical ID's are writing it.)

Since the user doesn't control the ID, and I've seen this happen when coding in pure WINAPI/ Powerbasic.. I know its a potential problem for this ID. I just wanted you to be aware that it seems to be happening..

To Test:
1) Build a simple with a Dialog, ComboBox, and Textbox (with multi-line style)
2) Save the Dialog as Dialog1, then rename it to Dialog2..
3) Now if you read Dialog1 back into your project the two textboxes, in theory would have the same ID..
4) Now if you play with the copy/paste events may encounter the problem I'm seeing.

These dialogs were made, from a copy.. similar to above. And then changes were added..

Thanks,
I will try your suggestion..
Explorations RPG System
"RPG Makers come & Go, But Explorations is Forever!"
http://www.explore-rpg.com

Exploration Gaming

Ok..

When I add the Control/Shift check you recommended, it doesn't keep the Control+I from being sent to the text box.. For example if I highlight a block of text to set it bold. When I press Control+B, it will set the bold around the text, but it doesn't suppress the Ctrl+B data from sending to the textbox. How do I keep the actual key from being sent to the textbox?

Explorations RPG System
"RPG Makers come & Go, But Explorations is Forever!"
http://www.explore-rpg.com

Paul Squires

Hi,

Could you maybe post a simple demo project of what you are doing. I want to help but it is hard to know exactly where to offer advice because a lot depends on how you are interacting with the TextBox and what other Windows messages maybe firing. In this case it may come down to having to intercept the messages at a lower level than the WM_KEYDOWN for the TextBox (that is, using the FF_PUMPHOOK handler).

From my understanding so far, you are catching the CTRL+B, calling some function of yours to change the font to bold for the highlighted portion of text, and then you want to eat the CTRL+B. The CTRL+B ultimately going to your TextBox shouldn't display anything in the TextBox. You may get a "beep"/"bell" sound though. What do you see in your TextBox when Ctrl+B is pressed (without first calling any type of user defined "bold" function)?


Paul Squires
PlanetSquires Software

Exploration Gaming

Yea.. Its hard to explain... So I will do it in steps.. The info in "quotes" is what the textbox contains..

1. "This is my bold test."

(I highlight the word "bold" and press control+b... I see)

2. "This is my   test"

(when I press control+z, to undo the change..I see....)

3) "This is my (b)bold(/b) test."  <- This is what I want to happen with control+b, I want to intercept, make the change and stop the key from proceeding to the textbox.

So on key down, I grab the selected text and surround it by (b)(/b).. But the selected text is replaced by a tab or some form of invisible/control characters..

Hope you understand now.. Parenthesis are actually brackets.

Explorations RPG System
"RPG Makers come & Go, But Explorations is Forever!"
http://www.explore-rpg.com