Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / using the button click and enter key

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. using the button click and enter key
#1175
Posted by: 2004-03-07 08:19:35
im using the onclick statement with a button and i would like to use the enter key also but when i do the onclick and onenter i get an error. it just wont take the onenter.  can you help. thanks.
Message2. Re: using the button click and enter key
#1176
Posted by: 2004-03-09 03:38:49
This condition is a bit tricky. You can't use .OnClick since it will capture button void action either by keyboard (space and enter) or by mouse click. If you want to determine user validate button by specific actions, you need to use .OnKeyUp and .OnMouseDown to isolate each input access. See example below:

 DECLARE SUB keypress(key AS BYTE)
 DECLARE SUB mouseclk

 CREATE form AS QFORM
  CREATE mybtn AS QBUTTON
   CAPTION = "click me"
   onkeyup = keypress
   onmousedown = mouseclk
  END CREATE
  SHOWMODAL
 END CREATE

 SUB keypress(key AS BYTE)
  IF key=13 THEN
   SHOWMESSAGE "Enter key"
  ELSE
   SHOWMESSAGE "Other key"
  END IF
 END SUB

 SUB mouseclk
  SHOWMESSAGE "mouse click"
 END SUB
Don

Message3. Re: using the button click and enter key
#1177
Posted by: 2004-03-10 01:35:20
You can activate a button by either clicking with the mouse OR by pressing Enter when the "focus" (you know, the ugly dotted line) is on that button. At the very start of your program add this line;

     Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

For each control element set the TabOrder property so that by using the Tab key (or Shift + Tab) you can step from one control element to the next (previous). Then when the focus is at the right control Enter will work.

The above line allows you to set the "focus" in your program. Let's say you have a button called HitMe, then putting the line

     SetFocus( HitMe .Handle)

(anywhere) in your program will set the "focus" to the HitMe button.

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥1,800.00 ·
 
 
¥489.00 ·
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥748.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0