Real Software Forums
http://forums.realsoftware.com/

Keyboard and Keycodes question
http://forums.realsoftware.com/viewtopic.php?f=10&t=47664
Page 1 of 1

Author:  plunkettphoto [ Sun Apr 21, 2013 6:28 pm ]
Post subject:  Keyboard and Keycodes question

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

Author:  timhare [ Sun Apr 21, 2013 6:40 pm ]
Post subject:  Re: Keyboard and Keycodes question

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.

Author:  plunkettphoto [ Mon Apr 22, 2013 10:21 am ]
Post subject:  Re: Keyboard and Keycodes question

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

Author:  msssltd [ Mon Apr 22, 2013 11:09 am ]
Post subject:  Re: Keyboard and Keycodes question

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

Author:  plunkettphoto [ Mon Apr 22, 2013 11:58 am ]
Post subject:  Re: Keyboard and Keycodes question

thanks msssltd

that worked like a champ,

b

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/