News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Test a toy for me.

Started by hutch--, June 26, 2005, 02:07:27 AM

Previous topic - Next topic

hutch--

Sorry to wear you out but I have another way of processing the return value from GetKeyState() as follows. This one is working OK on both my boxes so it might do the job. I have not changed the redraw issue but I am hoping that the key adjustments now work properly on XP. Arrow keys for fine adjustment, arrow keys & SHIFT for sizing the buttons.


        invoke GetKeyState,VK_SHIFT
        and eax, 10000000000000000000000000000000b
        jz over

        switch wParam           ; change size
          case VK_LEFT
            sub pt2.x, 1
          case VK_RIGHT
            add pt2.x, 1
          case VK_UP
            sub pt2.y, 1
          case VK_DOWN
            add pt2.y, 1
        endsw
        jmp past

      over:
        switch wParam           ; move position
          case VK_LEFT
            sub pt1.x, 1
          case VK_RIGHT
            add pt1.x, 1
          case VK_UP
            sub pt1.y, 1
          case VK_DOWN
            add pt1.y, 1
        endsw

      past:

        invoke MoveWindow,hCtl,pt1.x,pt1.y,pt2.x,pt2.y,TRUE

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM


Eóin

Doesn't work on XP for me either.

hutch--, check out this msdn example on using the wParam of WM_KEYDOWN instead of calling GetKeyState.

zooba

IIRC, GetKeyState returns values of 0, 1, -127 and -128. I can't remember exactly what each bit means but it is restricted to a single byte. MSDN says the 'high-order bit' is set if the key is pressed, which in a SHORT (WORD) value would be 8000h or 8001h. In practise, the WORD would normally be 0FF80h or 0FF81h. Shame the documentation isn't any better.

BTW, GetKeyState sends a message requesting the state of a key whereas GetAsyncKeyState gets the interrupt-level state associated with the hardware.  :U

hutch--

Thanks guys, these version differences nearly drive me nuts. I tested GetKeyState() with both of the specified bits set or clear and it ran as either a toggle or a one off kit. From the return value in eax I tried,


        and eax, 10000000000000000000000000000000b  ; one off key hit
        and eax, 00000000000000000000000000000001b  ; toggle key alternate


I am already trapping the arrow keys from the wParam for WM_MOUSE MOVE so that is not the problem, its trapping the shift key reliably as well that is the problem on XP and I dont have a box set up with XP.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Eóin

Hi --hutch, I just ran a quick check of the return values from "invoke GetKeyState,VK_SHIFT" on XP. They are

No key pressed: eax = 0h or 1h
Shift key pressed: eax = FFFFFF81h ro FFFFFF80h.

Maybe that'll be helpful to you.

Ghirai

Tested @ work on 2k sp4 and 2k server, works fine.
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

hutch--

I used Eóin's suestion and tested the two values and it appears to be working fine in my win2k box. I wrote up a test piece in binary notation output and the results were unusual. It seems the terminology for high order and low order bit ALA Microsoft apply on to the AL register, not EAX the return value.

I did the test with,


            invoke GetKeyState,VK_SHIFT

            cmp al, 10000000b
            je lbl1

            cmp al, 10000001b
            je lbl2


and the results verified the toggle state of the key.

I have attached the project with source this time as it is almost reliable.

Same as before, draw a button and then move it with the arrow keys for fine adjustment, arrow keys and Shift change the right or bottom side of the button while sizing.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

still doesn't work on xp - you must be getting frustrated!

do you want me to do any testing?

Mark Jones

It works fine for me on XP SP2... left-click and drag in the main window to create a "button" then (while selected) use the arrow keys to move it.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

AeroASM

but when you hold shift and use the arrow keys it moves instead of resizing...

Mark Jones

Whoops, missed that part. :green
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

hutch--

I have attached a test piece to try and find what the difference is with XP over win2k and win9x with the return values from GetKeyState().

With the bin toggle button I get with NO Shift key pressed,

00000000000000000000000000000000
or
00000000000000000000000000000001


With the Shift key pressed, I get,


11111111111111111111111110000000
or
11111111111111111111111110000001


The second button titled No Toggle has the toggle bit masked out while the third button does not. Both the second and third button work on AL only from the return value of GetKeyState().

Sorry to wear you out but the results have been very unpredictable on XP where they work perfectly on win9x and win2k.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zooba

Thanks for including your code in the most recent file Hutch ;-)

You've got this code:

        invoke GetKeyState,VK_SHIFT
        .if eax == 0FFFFFF81h || eax == 0FFFFFF80h
          jmp over
        .endif


Change it to:

        invoke GetKeyState,VK_SHIFT
        test al, 80h
        jnz over


and it works fine on WinXP  :U

My guess is that pre-WinXP GetKeyState negated the return value if the key is down whereas WinXP simply sets the (mildly) appropriate bit. The function is not well documented, maybe this will help  :P

chep

Hi,

I just tried both the first and the latest version, and both work fine here on WinXP (no service pack) / french keyboard.

zooba's fix also works fine (tested on the latest version SELECT03.ZIP).