[Solved] Keyboard advice

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 48
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

[Solved] Keyboard advice

Post by AndyGable » Monday 15th February 2021 3:50pm

Hi All,

I was hoping someone could help me with this

I have a question how do I detect the differance between the Key a being pressed and then then Key A being pressed?

Basically I have need to have different actions happen when the Key a is pressed and another function happen when Key A is pressed

any advice would be most welcomed as I have no idea and I can not even detect the differance in VB.net and no one seems to be able to tell me there either.
Last edited by AndyGable on Tuesday 16th February 2021 3:55pm, edited 1 time in total.

User avatar
PJBlack
Posts: 103
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Keyboard advice

Post by PJBlack » Monday 15th February 2021 4:21pm

Public Sub Form_KeyPress()

    Debug "Code: "; Key.Code, "Shift: "; Key.Shift

End

User avatar
cogier
Site Admin
Posts: 646
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Keyboard advice

Post by cogier » Monday 15th February 2021 4:44pm

And here is my input: -
Public Sub Form_KeyPress()

  Dim iKey As Integer
  
  If Not Key.Shift Then iKey = 32
  iKey += Key.Code
  If iKey > 64 And iKey < 123 Then Print Chr(iKey)

End

User avatar
BruceSteers
Posts: 390
Joined: Thursday 23rd July 2020 5:20pm

Re: Keyboard advice

Post by BruceSteers » Monday 15th February 2021 8:54pm

Does Key.Text not show a or A ?

If Key.Text Then
Select Key.Text
Case "a"

Case "A"
End Select

Endif

Not at home to test it.

Bruce
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
grayghost4
Posts: 83
Joined: Wednesday 05th December 2018 5:00am
Location: Concord, CA usa

Re: Keyboard advice

Post by grayghost4 » Monday 15th February 2021 9:15pm

Yes it does
Public Sub Form_KeyPress()


 Select Key.Text
Case "a"
  Print "a"

Case "A"
  Print "A"
End Select
 
End

AndyGable
Posts: 48
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: Keyboard advice

Post by AndyGable » Tuesday 16th February 2021 3:54pm

BruceSteers wrote:
Monday 15th February 2021 8:54pm
Does Key.Text not show a or A ?

If Key.Text Then
Select Key.Text
Case "a"

Case "A"
End Select

Endif

Not at home to test it.

Bruce
Thanks Bruce this worked perfectly I can now detect the difference between the keys and not relaying on key scan codes etc
so it is quicker :)

User avatar
BruceSteers
Posts: 390
Joined: Thursday 23rd July 2020 5:20pm

Re: Keyboard advice

Post by BruceSteers » Tuesday 16th February 2021 5:21pm

AndyGable wrote:
Tuesday 16th February 2021 3:54pm
BruceSteers wrote:
Monday 15th February 2021 8:54pm
Does Key.Text not show a or A ?

If Key.Text Then
Select Key.Text
Case "a"

Case "A"
End Select

Endif

Not at home to test it.

Bruce
Thanks Bruce this worked perfectly I can now detect the difference between the keys and not relaying on key scan codes etc
so it is quicker :)
You are welcome :)
The other suggestions will still help if you want to check for non alphabetical keys like F3, TAB, etc with shift differences but for any alphabetical text key Key.Text would do it.

Bruce
Wishing well
Bruce

If at first you don't succeed , try it differently.

Post Reply