Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Dec 13, 2017 5:38 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Keyboard and Keycodes question
PostPosted: Sun Apr 21, 2013 6:28 pm 
Offline
User avatar

Joined: Fri Oct 10, 2008 7:14 pm
Posts: 94
2 questions related to the list of KeyCodes given in the Keyboard module of the Language Reference.

First, why are capital letters not listed and the example says 00 is a capital A when the list shows 00 as lower case a.

Second, how do you trap for the enter key. Is the code for the main enter key the same as the code for the enter on the keypad?

I want to trap for the enter key in a text field and if pressed execute the code that's in the action event of a different pushbutton.

thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard and Keycodes question
PostPosted: Sun Apr 21, 2013 6:40 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Keycodes identify the physical key on the keyboard, so there is no difference between upper and lower case. But if you're doing this in a textfield, use the KeyDown event and forget about keycodes.


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard and Keycodes question
PostPosted: Mon Apr 22, 2013 10:21 am 
Offline
User avatar

Joined: Fri Oct 10, 2008 7:14 pm
Posts: 94
Function KeyDown(Key As String) As Boolean
dim sKeyEntered As String

sKeyEntered = key
if sKeyEntered = "0D" then
MsgBox("Enter")
end if

Return true

End Function


Ok, I'm missing something, like where are the definitions of the "keys" pressed in the keydown event. I want to test for the ENTER key being pressed and I can't seem to find out what what to test FOR. What do I need to do?

thanks,
b


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard and Keycodes question
PostPosted: Mon Apr 22, 2013 11:09 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
Here is an example, reworked from the Language Reference

Sub KeyDown(key as string) as boolean

//note that 'key' is a string - the binary representation of single character
// Key is converted to an ordinal representation using Asc(key)
Select Case key.Asc
Case &h0D //Return key pressed
Case &h03 //Enter key on numeric keypad pressed
Case &h20 //Space bar pressed
End Select


I think using the hex literal notation (&h00) is confusing in this instance. I used hex literals in the example to help highlight where you have misunderstood. Plain old decimal 13, 3, 32 works just as well.

I find the quickest way to find the right number is to test it yourself.
Sub KeyDown( key as string) as boolean
dim ch as integer = key.Asc
TextArea1.AppendText "You pressed the key " + Str(ch) + EndOfLine
End

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard and Keycodes question
PostPosted: Mon Apr 22, 2013 11:58 am 
Offline
User avatar

Joined: Fri Oct 10, 2008 7:14 pm
Posts: 94
thanks msssltd

that worked like a champ,

b


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group