Ctrl-ArrowUp/Down/Home/end

General FreeBASIC programming questions.
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 12:54

Since I have Windows10 the Ctrl-ArrowUp/Down and Ctrl-Home/End wont give a code so I con't use them. Is there a solution?
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Ctrl-ArrowUp/Down/Home/end

Postby vdecampo » Aug 15, 2016 13:28

Tested on Windows 10

Code: Select all

#Include "fbgfx.bi"
Using FB

Do
   
   If MultiKey(SC_UP) Then
      Print "UP"
   EndIf
   
   If MultiKey(SC_DOWN) Then
      Print "DOWN"
   EndIf
   
   If MultiKey(SC_LEFT) Then
      Print "LEFT"
   Endif
   
   If MultiKey(SC_RIGHT) Then
      Print "RIGHT"
   EndIf
      
loop Until InKey=Chr(27)



-Vince
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 13:36

Thank you, but this handle the 4 arrow-keys, and they report always, also without Ctrl key.
Now I am busy with a code with Multikey, but it is not yet good.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Ctrl-ArrowUp/Down/Home/end

Postby vdecampo » Aug 15, 2016 13:42

Code: Select all

#Include "fbgfx.bi"
Using FB

Do
   
   If MultiKey(SC_CONTROL) Then
      
      If MultiKey(SC_UP) Then
         Print "CTRL-UP"
      EndIf
      
      If MultiKey(SC_DOWN) Then
         Print "CTRL-DOWN"
      EndIf
      
      If MultiKey(SC_LEFT) Then
         Print "CTRL-LEFT"
      Endif
      
      If MultiKey(SC_RIGHT) Then
         Print "CTRL-RIGHT"
      EndIf
      
      If MultiKey(SC_HOME) Then
         Print "CTRL-HOME"
      EndIf
            
      If MultiKey(SC_END) Then
         Print "CTRL-END"
      EndIf                  
                  
   End If
   
loop Until InKey=Chr(27)


-Vince
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 14:41

Okay, im on the way. But there is no keypause. I'm busy with it, but it's not yet good. I post it if I found the right way.
Tourist Trap
Posts: 2768
Joined: Jun 02, 2015 16:24

Re: Ctrl-ArrowUp/Down/Home/end

Postby Tourist Trap » Aug 15, 2016 14:47

Jawade wrote:Okay, im on the way. But there is no keypause. I'm busy with it, but it's not yet good. I post it if I found the right way.

After each complete multikey interception, it's advised to clean-up for the next round:

Code: Select all

while inkey()<>"" : wend

It's explained in Multikey documentation.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Ctrl-ArrowUp/Down/Home/end

Postby vdecampo » Aug 15, 2016 16:08

This provides single key-press functionality...

Code: Select all

#Include "fbgfx.bi"
Using FB

Enum KeyModifiers
   NONE = 0,
   CTRL = 1,
   ALT = 2
End Enum

Function KeyPress(ByRef key As Integer, ByRef modifier As Integer) As Integer
Static lastkey As Integer
Static lastmodifier As Integer

   modifier = KeyModifiers.NONE
   key=0

   For k As Integer = 0 To 255
      If MultiKey(k) Then
         If (lastkey = k) And (modifier = lastmodifier) Then            
            Return 0            
         Else      
            If (k=SC_ALT) or (k=SC_CONTROL) Then
               If k = SC_CONTROL Then modifier Or= KeyModifiers.CTRL
               If k = SC_ALT Then modifier Or= KeyModifiers.ALT                  
            Else               
               key = k
               lastkey = k
               lastmodifier = modifier
               Return 1
            End If
         EndIf
      EndIf      
   Next   
   
   lastkey = 0   
   lastmodifier = KeyModifiers.NONE
            
   Return 0
            
End Function


Dim Modify As Integer
Dim KeyCode As Integer

Do
   
   If KeyPress(KeyCode, Modify) Then
                
        If Modify = KeyModifiers.CTRL Then      
         Select case KeyCode                   
            Case SC_UP:
                Print "CTRL-UP Pressed!"
            Case SC_DOWN:
                Print "CTRL-DOWN Pressed!"
            Case SC_LEFT:
                   Print "CTRL-LEFT Pressed!"
            Case SC_RIGHT:
                   Print "CTRL-RIGHT Pressed!"
         End Select
        EndIf
        
        If Modify = KeyModifiers.ALT Then
         Select case KeyCode                   
            Case SC_UP:
                Print "ALT-UP Pressed!"
            Case SC_DOWN:
                Print "ALT-DOWN Pressed!"
            Case SC_LEFT:
                   Print "ALT-LEFT Pressed!"
            Case SC_RIGHT:
                   Print "ALT-RIGHT Pressed!"
         End Select
      EndIf
                
   End If
   
loop Until InKey=Chr(27)



-Vince
Last edited by vdecampo on Aug 15, 2016 16:11, edited 1 time in total.
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 16:11

I dont know what you mean.

This is what I have, but it don't work perfectly:

Code: Select all

Dim Shared dly As Integer
Dim Shared aa As String

Main:
  Do
    Do
      dly = 50
      aa = InKey$: Sleep 3
    Loop Until aa <> "" Or MultiKey(29) <> 0
'    dly = dly - 1
'    If MultiKey(29) <> 0 Then dly = 50
    If MultiKey(29) Then
      If dly <> 50 Then
        If dly Then Do: dly = dly - 1: Sleep 1: Loop Until dly < 1
      Else
        dly = dly - 1
'      End If
      If MultiKey(73) Then Print 132
      If MultiKey(81) Then Print 118
      If MultiKey(82) Then Print 146
      If MultiKey(83) Then Print 147
      If MultiKey(75) Then Print 115
      If MultiKey(77) Then Print 116
      If MultiKey(80) Then Print 145
      If MultiKey(72) Then Print 141
      If MultiKey(79) Then Print 117
      If MultiKey(71) Then Print 119
      End If
    End If
    If MultiKey(29) = 0 And Len(aa) = 2 Then Print Asc(Mid$(aa, 2))
    If MultiKey(29) = 0 And Len(aa) = 1 Then Print Asc(aa)
  Loop Until aa = Chr$(27)
System
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 16:24

Thanks, but it do not repeat like a normal inkeyvalue. What I exactly want, is a pause after keypress, and after a while repeat. In my code the repeat works, but te pause no not. And that is what I want.
dodicat
Posts: 6022
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Ctrl-ArrowUp/Down/Home/end

Postby dodicat » Aug 15, 2016 18:40

1) Set the framerate (60 F.P.S. chosen)
2) Set a flag for single keypress functionality (Like vdecampo's)
3) Use a counter to act as a timer for an event, the event is override the single keypress functionality.
I use one second between repeats.

Code: Select all

#Include "fbgfx.bi"
Using FB


'=================== FRAME SPEED REGULATOR ============================
Function Regulate(Byval MyFps As Integer,Byref fps As Integer=0) As Integer
    Static As Double timervalue,lastsleeptime,t3,frames
    Var t=Timer
    frames+=1
    If (t-t3)>=1 Then t3=t:fps=frames:frames=0
    Var sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
    If sleeptime<1 Then sleeptime=1
    lastsleeptime=sleeptime
    timervalue=T
    Return sleeptime
End Function
'====================================================================
dim as long flag
dim as long counter
Do
counter+=1
 if counter>60 then flag=0  'produces a lag period
   If MultiKey(SC_CONTROL)  Then
       
      If MultiKey(SC_UP) and flag=0 Then
          flag=1
          counter=0
         Print "CTRL-UP   "
      End If
     
      If MultiKey(SC_DOWN) and flag=0 Then
           flag=1
           counter=0
         Print "CTRL-DOWN "
      End If
     
      If MultiKey(SC_LEFT) and flag=0 Then
           flag=1
           counter=0
         Print "CTRL-LEFT "
      End if
     
      If MultiKey(SC_RIGHT) and flag=0 Then
           flag=1
           counter=0
         Print "CTRL-RIGHT"
      End If
     
      If MultiKey(SC_HOME) and flag=0 Then
           flag=1
           counter=0
         Print "CTRL-HOME "
      End If
           
      If MultiKey(SC_END) and flag=0 Then
           flag=1
           counter=0
         Print "CTRL-END  "
      End If                 
                 
   Else
       flag=0
   end if
sleep regulate(60),1  '60 frames per second
loop Until InKey=Chr(27)
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Ctrl-ArrowUp/Down/Home/end

Postby vdecampo » Aug 15, 2016 19:30

Now with adjustable repeat rate...

Code: Select all

#Include "fbgfx.bi"
Using FB

Enum KeyModifiers
   NONE = 0,
   CTRL = 1,
   ALT = 2
End Enum



Function KeyPress(ByRef key As Integer, ByRef modifier As Integer) As Integer
Dim As double repeatwait = .3
Static lastkey As Integer
Static lastmodifier As Integer
Static tmrrepeat As Double

   modifier = KeyModifiers.NONE
   key=0

   For k As Integer = 0 To 255
      If MultiKey(k) Then
         If (lastkey = k) And (modifier = lastmodifier) Then
            If Timer - tmrrepeat > repeatwait Then
               lastkey = 0
               lastmodifier = 0
               tmrrepeat = timer
            EndIf
            Return 0           
         Else     
            If (k=SC_ALT) or (k=SC_CONTROL) Then
               If k = SC_CONTROL Then modifier Or= KeyModifiers.CTRL
               If k = SC_ALT Then modifier Or= KeyModifiers.ALT                 
            Else               
               key = k
               lastkey = k
               lastmodifier = modifier
               Return 1
            End If
         EndIf
      EndIf     
   Next   
   
   lastkey = 0   
   lastmodifier = KeyModifiers.NONE
   tmrrepeat = Timer
           
   Return 0
           
End Function


Dim Modify As Integer
Dim KeyCode As Integer

Do
   
   If KeyPress(KeyCode, Modify) Then
               
        If Modify = KeyModifiers.CTRL Then     
         Select case KeyCode                   
            Case SC_UP:
                Print "CTRL-UP Pressed!"
            Case SC_DOWN:
                Print "CTRL-DOWN Pressed!"
            Case SC_LEFT:
                   Print "CTRL-LEFT Pressed!"
            Case SC_RIGHT:
                   Print "CTRL-RIGHT Pressed!"
         End Select
        EndIf
       
        If Modify = KeyModifiers.ALT Then
         Select case KeyCode                   
            Case SC_UP:
                Print "ALT-UP Pressed!"
            Case SC_DOWN:
                Print "ALT-DOWN Pressed!"
            Case SC_LEFT:
                   Print "ALT-LEFT Pressed!"
            Case SC_RIGHT:
                   Print "ALT-RIGHT Pressed!"
         End Select
      EndIf
               
   End If
   
loop Until InKey=Chr(27)


-Vince
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 19:34

Thanks, but it do not do what I mean. Look at mij program, it is not good but you can see what I mean. The Ctrl-keys have to react lijke the non-Ctrl keys.

Code: Select all

Dim Shared dly As Integer
Dim Shared aa As String

Main:
  Do
    Do
      aa = InKey$: Sleep 3
    Loop Until aa <> "" Or MultiKey(29) <> 0
    If MultiKey(29) <> 0 Or aa <> "" Then dly = 50
    If MultiKey(29) Then
      If dly = 50 Then
        If dly Then Do: dly = dly - 1: Sleep 1: Loop Until dly < 1
      End If
      If MultiKey(73) Then Print 132
      If MultiKey(81) Then Print 118
      If MultiKey(82) Then Print 146
      If MultiKey(83) Then Print 147
      If MultiKey(75) Then Print 115
      If MultiKey(77) Then Print 116
      If MultiKey(80) Then Print 145
      If MultiKey(72) Then Print 141
      If MultiKey(79) Then Print 117
      If MultiKey(71) Then Print 119
    End If
    If MultiKey(29) = 0 And Len(aa) = 2 Then Print Asc(Mid$(aa, 2))
    If MultiKey(29) = 0 And Len(aa) = 1 Then Print Asc(aa)
  Loop Until aa = Chr$(27)
System
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Ctrl-ArrowUp/Down/Home/end

Postby vdecampo » Aug 15, 2016 19:37

[quote="Jawade"]Thanks, but it do not do what I mean. Look at mij program, it is not good but you can see what I mean. The Ctrl-keys have to react lijke the non-Ctrl keys.
[code]

Well you are free to modify my code to work as you like.

-Vince
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 19:42

It's almost right Vince, but I want a pause and If you stay press the key, a fast repeat, just like the notmal inkey keys. See mij example on mij before message. The result have to be just like how it was when the Ctrl-arrow keys did a normal act.
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Ctrl-ArrowUp/Down/Home/end

Postby Jawade » Aug 15, 2016 19:47

The pre-last reaction was not to you Vince. Of corse I can edit the example. But I think my program komes very close to my goal, but not far enaugh, so look at that.

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest