[Solved] Keyboard advice

Post

Posted
Rating:
#1 (In Topic #583)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’

Code (gambas)

  1. Public Sub Form_KeyPress()
  2.  
  3.     Debug "Code: "; Key.Code, "Shift: "; Key.Shift
  4.  
  5.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
And here is my input: -

Code (gambas)

  1. Public Sub Form_KeyPress()
  2.  
  3.   Dim iKey As Integer
  4.  
  5.   If Not Key.Shift Then iKey = 32
  6.   iKey += Key.Code
  7.   If iKey > 64 And iKey < 123 Then Print Chr(iKey)
  8.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
 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
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
Yes it does

Code (gambas)

  1. Public Sub Form_KeyPress()
  2.  
  3.  
  4.  Select Key.Text
  5. Case "a"
  6.   Print "a"
  7.  
  8. Case "A"
  9.   Print "A"
  10.  
Online now: No Back to the top

Post

Posted
Rating:
#6
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

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 :)
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

BruceSteers said

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
Online now: No Back to the top
1 guest and 0 members have just viewed this.