NUMLOCK and SCREENEVENT

General FreeBASIC programming questions.
Sisophon2001
Posts: 1704
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

NUMLOCK and SCREENEVENT

Postby Sisophon2001 » Dec 16, 2007 3:25

When I use screenevent it reports SC_LEFT when I press 4 on the number pad, regardless of whether the NUM LOCK light is on or off. I have difficulty getting just the number pressed without the arrow keys (which I must also detect).

Am I missing some obvious way to get the numbers only?

Garvan

P.S. Code tested on Linux, and I want it to work on bothe Linux and windows.

Code: Select all

#include "fbgfx.bi"
dim as fb.event e
dim as integer num

screenres 640, 480

do

   if screenevent(@e) then
      if e.type = FB.EVENT_KEY_PRESS or _
            e.type = FB.EVENT_KEY_REPEAT then

         select case e.scancode
         case FB.SC_DOWN
            locate 1,1
            print "SC_DOWN "
         case FB.SC_UP
            locate 1,1
            print "SC_UP   "
         case FB.SC_LEFT
            locate 1,1
            print "SC_LEFT "
         case FB.SC_RIGHT
            locate 1,1
            print "SC_RIGHT"
         case FB.SC_ESCAPE
            exit do
         end select
      end if
   end if
loop
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Postby Merick » Dec 16, 2007 21:22

just tested your code, I get the same behavior on winxp
Sisophon2001
Posts: 1704
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Postby Sisophon2001 » Jan 12, 2008 10:49

This is my attempt at detecting NumLock. Please let me know if there are problems with it.

Garvan

Code: Select all

#include "fbgfx.bi"
dim as fb.event e
dim as integer num

screenres 640, 480

do
    if screenevent(@e) then
        if e.type = FB.EVENT_KEY_PRESS or _
            e.type = FB.EVENT_KEY_REPEAT then
            cls
            locate 1,1
            select case e.scancode
            case FB.SC_DOWN
                if e.ascii >= asc("0") and e.ascii <= asc("9") then
                    print chr(e.ascii)
                else
                    print "SC_DOWN"
                end if
            case FB.SC_UP
                if e.ascii >= asc("0") and e.ascii <= asc("9") then
                    print chr(e.ascii)
                else
                    print "SC_UP"
                end if
            case FB.SC_LEFT
                if e.ascii >= asc("0") and e.ascii <= asc("9") then
                    print chr(e.ascii)
                else
                    print "SC_LEFT"
                end if
            case FB.SC_RIGHT
                if e.ascii >= asc("0") and e.ascii <= asc("9") then
                    print chr(e.ascii)
                else
                    print "SC_RIGHT"
                end if
            case FB.SC_ESCAPE
                exit do
            case else
                print chr(e.ascii)
            end select
        end if
    end if
loop
elsairon
Posts: 207
Joined: Jul 02, 2005 14:51

Postby elsairon » Jan 12, 2008 18:57

Works great here, fbc 0.18.3 on winxp.

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests