LB Booster
« Detecting a key release? »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:35am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Detecting a key release?  (Read 363 times)
SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: Detecting a key release?
« Reply #17 on: Feb 6th, 2018, 1:24pm »

Anatoly,

Here is the demo,

Code:
REM Keypress Key Release Demo By Sarmed Nafi'
REM Keys and Shift + Key
REM Keys F2  F3  Up  Down  Left  Right  Shift + Left  Shift + Right
REM Works with LBB better than LB
timer 1, [loop]   
[loop]
  scan
    if (keyState(_VK_F2 )=1) AND (F2=0) then '      >>  >>  F2
      F2=1
      PRINT "F2  pressed" : PRINT
    else
    if (keyState(_VK_F2 )=0) AND (F2=1) then 'Reset
      F2=0
      PRINT "F2  released" : PRINT
    else 
    if (keyState(_VK_F3 )=1) AND (F3=0) then '      >>  >>  F3
      F3=1
      PRINT "F3  pressed" : PRINT
    else
    if (keyState(_VK_F3 )=0) AND (F3=1) then 'Reset
      F3=0
      PRINT "F3  released" : PRINT
    else
    if (keyState(_VK_UP )=1) AND (up=0) AND (Fhndl=hDate) then ' >>  >>  UP 
      up=1
      PRINT "Up Arrow  pressed" : PRINT
    else
    if (keyState(_VK_UP )=0) AND (up=1) then 'Reset
      up=0
      PRINT "Up Arrow  released" : PRINT
    else
    if (keyState(_VK_DOWN )=1) AND (dwn=0) AND (Fhndl=hDate) then '  >>  >>  Dwn 
      dwn=1
      PRINT "Down Arrow  pressed" : PRINT
    else
    if (keyState(_VK_DOWN )=0) AND (dwn=1) then 'Reset
      dwn=0
      PRINT "Down Arrow  released" : PRINT
    else
    if (keyState(_VK_RIGHT )=1) AND (Rt=0) AND (keyState(_VK_SHIFT )=0) then ' >>  >>  Right
      Rt=1
      PRINT "Right Arrow  pressed" : PRINT
    else
    if (keyState(_VK_RIGHT )=0) AND (Rt=1) AND (keyState(_VK_SHIFT )=0) then 'Reset
      Rt=0
      PRINT "Right Arrow  released" : PRINT
    else
    if (keyState(_VK_RIGHT )=1) AND (shRt=0) AND (keyState(_VK_SHIFT )=1) then ' >>  >>  Shift + Right
      shRt=1
      PRINT "Shift + Right Arrow  pressed" : PRINT
    else
    if (keyState(_VK_RIGHT )=0) AND (shRt=1) AND (keyState(_VK_SHIFT )=1) then 'Reset
      shRt=0
      PRINT "Shift + Right Arrow  released" : PRINT
    else
    if (keyState(_VK_LEFT )=1) AND (lft=0) AND (keyState(_VK_SHIFT )=0) AND Grd=0 then '  >>  >>  Left
      lft=1
      PRINT "Left Arrow  pressed" : PRINT
    else
    if (keyState(_VK_LEFT )=0) AND (lft=1) AND (keyState(_VK_SHIFT )=0) then 'Reset
      lft=0
      PRINT "Left Arrow  released" : PRINT
    else
    if (keyState(_VK_LEFT )=1) AND (shlft=0) AND (keyState(_VK_SHIFT )=1) AND Grd=0 then ' >>  >>  Shift + Left
      shlft=1
      PRINT "Shift + Left Arrow  pressed" : PRINT
    else
    if (keyState(_VK_LEFT )=0) AND (shlft=1) AND (keyState(_VK_SHIFT )=1) then 'Reset
      shlft=0
      PRINT "Shift + Left Arrow  released" : PRINT
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    
  WAIT  
'------    
function keyState(keycode)
  calldll #user32, "GetAsyncKeyState", keycode AS Ulong, state AS short
  if state<0 then 
  keyState = 1
  else
  keyState = 0
  end if
  end function
'------
 


The code works under LBB better than LB.

Regards,
Sarmed.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Detecting a key release?
« Reply #18 on: Feb 6th, 2018, 2:58pm »

on Feb 6th, 2018, 1:24pm, SarmedNafi wrote:
The code works under LBB better than LB.

That code uses polling. This thread has been about the triggering (or not) of an event when a key is pressed or released.

Polling in a timer handler, as you do, and then calling the 'event' handler accordingly can be an acceptable workaround, but as Rod said it's not always a very satisfactory approach. For example it ties up the timer and, potentially, has a much greater latency than a true event.

Richard.
User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: Detecting a key release?
« Reply #19 on: Feb 6th, 2018, 9:38pm »

I remember that days I worked hard to find a way using INKEY$, unfortunately, INKEY$ is a simple command.
I think VB6 has the same mechanism inside its engine or similar to that I used to trap keyboard event.

Quote:
but as Rod said it's not always a very satisfactory approach.

Rod said that because he knows TIMER is broken under Liberty Basic.
I was made a very large search to discover how that big 3d games written under LB using TIMER command. The shock was they don't use the TIMER at all.
If anyone uses my code under LB he will put himself in trouble and be wasting his time. Then he will find there is no way but to use LBB.
When we were kids at sixties we advised each other "Don't ride a bicycle from Japan ride a bicycle from ENGLAND", It seems nothing change.

Sarmed
« Last Edit: Feb 6th, 2018, 10:11pm by SarmedNafi » User IP Logged

Monkfish
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 104
xx Re: Detecting a key release?
« Reply #20 on: Feb 7th, 2018, 09:32am »

Thanks guys, and thanks Rob for clearing up exactly how Inkey$ works. smiley

Btw, I haven't looked at LB for a while. I only use LBB. Thanks Richard for still being here for us grin
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls