Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inkey Literal Key Display
#1
So we press F1. Ever just wanted to see F1 displayed instead of: Chr$(0) + ; Huh 

Well now you can. Hey it was either that or buy you guys a Popeil Pocket Fisherman for X-mas.

Anyway, it works with the key combos available in INKEY$, too. The guts can are good for conversion uses, which funnily enough I had one of those that I backward engineered to make this demo.

Edit: Forum messed up some ascii characters, so I redid it using the QB64 IDE Export feature and that failed miserably, too.

So if only we had a forum that wouldn't MUCK UP a perfectly good code block without switching ascii characters like turning F's into M's... Oh wait, we do!

https://www.tapatalk.com/groups/qbasic/l...ml#p214281  Literal Inkey$ Code.

Pete

PS I'll add a zip file later; right now I'm too kissed, opay? 

Edit: Zip added. Two files. One with string characters, and one with string 'numbers'.

Now two issues, What sucks about GLUT is Ctrl + J and Ctrl + Enter both return Chr$(10) with Inkey, and if I used _KeyHit both would return Chr$(13). So when we press Ctrl + Enter its going to display Ctrl + J. Also, both Inkey$ and _KeyHit return like values for Ctrl + Delete and Ctrl + Backspace, so we have a key duplication error there as well. Everything else should display correctly, if not, it's a bug... I mean a feature!

Pete


Attached Files
.7z   inkey literal key display.7z (Size: 2.46 KB / Downloads: 9)
Reply
#2
The report output is not matching the keys I am pressing. I assume it is supposed to?
Nothing for enter, arrows ok but what's the W?
home, end, pgup and pgdn all mixed up?

do you want more? F12 is 2 ins, F1 - F10 look 0K. F11 is blank f1

Dang and this one had a reasonable amt of LOC!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
looking good!
   

+1 for your troubles Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#4
Well I think I will test the Export Code, and not edit this post.

Code: (Select All)
Type KeyPress
    Press As String
    shift As Integer
    ctrl As Integer
    alt As Integer
End Type
Dim k As KeyPress

KbUName$ = "f1        f2        f3        f4        f5        f6        f7        f8        f9        f10      f11      f12      insert    delete    pgup      pgdn      home      end      arrow lt  arrow up  arrow dn  arrow rt  backspace ~        !        @        #        $        %        ^        &        *        (        )        _        +        q        w        e        r        t        y        u        i        o        p        {        }        |        a        s        d        f        g        h        j        k        l        :        " + Chr$(34) + "        z        x        c        v        b        n        m        <        >        ?        space    tab      esc      enter"
KbLName$ = "f1        f2        f3        f4        f5        f6        f7        f8        f9        f10      f11      f12      insert    delete    pgup      pgdn      home      end      arrow lt  arrow up  arrow dn  arrow rt  backspace `        1        2        3        4        5        6        7        8        9        0        -        =        q        w        e        r        t        y        u        i        o        p        [        ]        \        a        s        d        f        g        h        j        k        l        ;        '        z        x        c        v        b        n        m        ,        .        /        space    tab      esc      enter"
KbU$ = ",84 ,85 ,86 ,87 ,88 ,89 ,90 ,91 ,92 ,93 ,133,134,82 ,83 ,73 ,81 ,71 ,79 ,75 ,72 ,80 ,77 ,8  ,126,33 ,64 ,35 ,36 ,37 ,94 ,38 ,42 ,40 ,41 ,95 ,43 ,81 ,87 ,69 ,82 ,84 ,89 ,85 ,73 ,79 ,80 ,123,125,124,65 ,83 ,68 ,70 ,71 ,72 ,74 ,75 ,76 ,58 ,34 ,90 ,88 ,67 ,86 ,66 ,78 ,77 ,60 ,62 ,63 ,32 ,15 ,27 ,13 "
KbL$ = ",59 ,60 ,61 ,62 ,63 ,64 ,65 ,66 ,67 ,68 ,133,134,82 ,83 ,73 ,81 ,71 ,79 ,75 ,72 ,80 ,77 ,8  ,96 ,49 ,50 ,51 ,52 ,53 ,54 ,55 ,56 ,57 ,48 ,45 ,61 ,113,119,101,114,116,121,117,105,111,112,91 ,93 ,92 ,97 ,115,100,102,103,104,106,107,108,59 ,39 ,122,120,99 ,118,98 ,110,109,44 ,46 ,47 ,32 ,9  ,27 ,13 "
Ctrlk$ = ",94 ,95 ,96 ,97 ,98 ,99 ,100,101,102,103,137,138,146,147,132,118,119,117,115,141,145,116,147,000,000,000,000,000,000,000,000,000,000,000,000,000,17 ,23 ,5  ,18 ,20 ,25 ,21 ,9  ,15 ,16 ,27 ,29 ,28 ,1  ,19 ,4  ,6  ,7  ,8  ,10 ,11 ,12 ,000,000,26 ,24 ,3  ,22 ,2  ,14 ,13 "
Altk$ = ",104,105,106,107,108,109,110,111,112,113,139,140,162,163,153,161,151,159,155,152,160,157,14 ,41 ,120,121,122,123,124,125,126,127,128,129,130,131,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,43 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 ,44 ,45 ,46 ,47 ,48 ,49 ,50 ,51 ,52 ,53 "
Do
    _Limit 30
    Keyboard k
    If Len(k.Press) Then
        e$ = Space$(3)
        If k.ctrl = _TRUE And k.alt = _TRUE Or k.alt Then
            Mid$(e$, 1) = LTrim$(Str$(Asc(Mid$(k.Press, 2, 1))))
            e$ = RTrim$(Mid$(KbLName$, (((InStr(Altk$, "," + e$)) + 3) \ 4) * 10 - 9, 10))
        ElseIf k.ctrl Then
            If Len(k.Press) = 1 Then Mid$(e$, 1) = LTrim$(Str$(Asc(k.Press))) Else Mid$(e$, 1) = LTrim$(Str$(Asc(Mid$(k.Press, 2, 1))))
            e$ = RTrim$(Mid$(KbLName$, (((InStr(Ctrlk$, "," + e$)) + 3) \ 4) * 10 - 9, 10))
        Else
            If Len(k.Press) = 1 Then Mid$(e$, 1) = LTrim$(Str$(Asc(k.Press))): seed = 89 Else Mid$(e$, 1) = LTrim$(Str$(Asc(Mid$(k.Press, 2, 1)))): seed = 0
            If k.shift Then tmp1$ = KbUName$: tmp2$ = KbU$ Else tmp1$ = KbLName$: tmp2$ = KbL$
            e$ = RTrim$(Mid$(tmp1$, (((InStr(seed, tmp2$, "," + e$)) + 3) \ 4) * 10 - 9, 10))
        End If
    End If
    If Len(e$) Then
        Print "Keypress: ";
        If k.shift Then Print "Shift ";
        If k.alt Then Print "Alt ";
        If k.ctrl Then Print "Ctrl ";
        If Len(e$) > 1 Then
            Print UCase$(Left$(e$, 1)) + Mid$(e$, 2)
        Else
            If k.shift Or k.alt Or k.ctrl Then Print UCase$(e$) Else Print e$
        End If
        e$ = ""
    End If
Loop

Sub Keyboard (k As KeyPress)
    k.Press = InKey$
    If _KeyDown(100303) Or _KeyDown(100304) Then k.shift = -1 Else If k.shift Then k.shift = 0
    If _KeyDown(100305) Or _KeyDown(100306) Then k.ctrl = -1 Else If k.ctrl Then k.ctrl = 0
    If _KeyDown(100307) Or _KeyDown(100308) Then k.alt = -1 Else If k.alt Then k.alt = 0
End Sub
Reply
#5
Well I'd like to eventually get one that will post without any problems on this forum, so I haven't added numlock to this routine, but before I do, let's test it out...

Code: (Select All)
Do
    _Limit 30
    b$ = InKey$
    If _KeyDown(100303) Or _KeyDown(100304) Then shift = -1 Else If shift Then shift = 0
    If _KeyDown(100305) Or _KeyDown(100306) Then ctrl = -1 Else If ctrl Then ctrl = 0
    If _KeyDown(100307) Or _KeyDown(100308) Then alt = -1 Else If alt Then alt = 0
    If Len(b$) Then
        Sound 1000, .2
        If alt Then
            Restore AltKeys
        ElseIf ctrl Then Restore CtrlKeys
        ElseIf shift Then Restore UcaseKeys Else Restore LcaseKeys
        End If
        If Len(b$) = 1 Then e = Asc(b$): seed = 22 Else e = Asc(Mid$(b$, 2, 1)): seed = 0
        i = 0
        Do
            i = i + 1
            Read a, key$
            If key$ = "eof" Then Exit Do
            If a = e And i > seed Then
                If shift Then
                    j = InStr("`1234567890-=[]\;',./", key$)
                    If j Then key$ = Mid$("~!@#$%^&*()_+{}|:'<>?", j, 1): If key$ = "'" Then key$ = Chr$(34)
                End If
                If key$ = "-Q" Then key$ = Chr$(34) ' Compensate for inability to store a quote mark in a data statement.
                If shift + ctrl + alt Then If Len(key$) = 1 Then key$ = UCase$(key$)
                If shift Then Print "Shift ";
                If ctrl Then Print "Ctrl "; Rem If key$ = "J" Then key$ = "Enter" GLUT error. BTW _Keyhit would return 13 for Ctrl + Enter or Ctrl + J.
                If alt Then Print "Alt ";
                Print key$: Exit Do
            End If
        Loop
    End If
Loop

UcaseKeys:
Data 84,F1,85,F2,86,F3,87,F4,88,F5,89,F6,90,F7,91,F8,92,F9,93,F10,133,F11,134,F12,82,Insert,83,Delete,73,PgUp,81,PgDn,71,Home,79,End,75,Arrow Lt,72,Arrow Up,80,Arrow Dn,77,Arrow Rt,8,Backspace,126,~,33,!,64,@,35,#,36,$,37,%,94,^,38,&,42,*,40,(,41,),95,_,43,+,81,Q,87,W,69,E,82,R,84,T,89,Y,85,U,73,I,79,O,80,P,123,{,125,},124,|,65,A,83,S,68,D,70,F,71,G,72,H,74,J,75,K,76,L,58,":",34,-Q,90,Z,88,X,67,C,86,V,66,B,78,N,77,M,60,<,62,>,63,?,32,Space,15,Tab,27,Esc,13,Enter,-1,eof

LcaseKeys:
Data 59,F1,60,F2,61,F3,62,F4,63,F5,64,F6,65,F7,66,F8,67,F9,68,F10,133,F11,134,F12,82,Insert,83,Delete,73,PgUp,81,PgDn,71,Home,79,End,75,Arrow Lt,72,Arrow Up,80,Arrow Dn,77,Arrow Rt,8,Backspace,96,`,49,1,50,2,51,3,52,4,53,5,54,6,55,7,56,8,57,9,48,0,45,-,61,=,113,q,119,w,101,e,114,r,116,t,121,y,117,u,105,i,111,o,112,p,91,[,93,],92,\,97,a,115,s,100,d,102,f,103,g,104,h,106,j,107,k,108,l,59,;,39,',122,z,120,x,99,c,118,v,98,b,110,n,109,m,44,",",46,.,47,/,32,Space,9,Tab,27,Esc,13,Enter,-1,eof

CtrlKeys:
Data 94,F1,95,F2,96,F3,97,F4,98,F5,99,F6,100,F7,101,F8,102,F9,103,F10,137,F11,138,F12,146,Insert,147,Delete,132,PgDp,118,PgDn,119,Home,117,End,115,Arrow Lt,141,Arrow Up,145,Arrow Dn,116,Arrow Rt,147,Backspace,17,q,23,w,5,e,18,r,20,t,25,y,21,u,9,i,15,o,16,p,1,a,19,s,4,d,6,f,7,g,8,h,10,j,11,k,12,l,26,z,24,x,3,c,22,v,2,b,14,n,13,m,32,Space,0,2,30,6,31,-,-1,eof

AltKeys:
Data 104,F1,105,F2,106,F3,108,F5,109,F6,110,F7,111,F8,112,F9,113,F10,139,F11,140,F12,162,Insert,163,Delete,153,PgDp,161,PgDn,151,Home,159,End,155,Arrow Lt,152,Arrow Up,160,Arrow Dn,157,Arrow Rt,14,Backspace,41,`,120,1,121,2,122,3,123,4,124,5,125,6,126,7,127,8,128,9,129,0,130,-,131,=,16,q,17,w,18,e,19,r,20,t,21,y,22,u,23,i,24,o,25,p,26,[,27,],43,\,30,a,31,s,32,d,33,f,34,g,35,h,36,j,37,k,38,l,39,;,40,',44,z,45,x,46,c,47,v,48,b,49,n,50,m,51,",",52,.,53,/,-1,eof

I also discovered Ctrl + Shift with then numbers 2, 6, and - key return values!

Pete

PS Rho should like this one, it's DATA lists... YUCK!
Reply
#6
Okay, that one worked. Let's try a string type now...

Code: (Select All)
UcaseKeys$ = ",84 F1,85 F2,86 F3,87 F4,88 F5,89 F6,90 F7,91 F8,92 F9,93 F10,133 F11,134 F12,82 Insert,83 Delete,73 PgUp,81 PgDn,71 Home,79 End,75 Arrow Lt,72 Arrow Up,80 Arrow Dn,77 Arrow Rt,8 Backspace,126 ~,33 !,64 @,35 #,36 $,37 %,94 ^,38 &,42 *,40 (,41 ),95 _,43 +,81 Q,87 W,69 E,82 R,84 T,89 Y,85 U,73 I,79 O,80 P,123 {,125 },124 |,65 A,83 S,68 D,70 F,71 G,72 H,74 J,75 K,76 L,58 :,34 -Q,90 Z,88 X,67 C,86 V,66 B,78 N,77 M,60 <,62 >,63 ?,32 Space,15 Tab,27 Esc,13 Enter"
LcaseKeys$ = ",59 F1,60 F2,61 F3,62 F4,63 F5,64 F6,65 F7,66 F8,67 F9,68 F10,133 F11,134 F12,82 Insert,83 Delete,73 PgUp,81 PgDn,71 Home,79 End,75 Arrow Lt,72 Arrow Up,80 Arrow Dn,77 Arrow Rt,8 Backspace,96 `,49 1,50 2,51 3,52 4,53 5,54 6,55 7,56 8,57 9,48 0,45 -,61 =,113 q,119 w,101 e,114 r,116 t,121 y,117 u,105 i,111 o,112 p,91 [,93 ],92 \,97 a,115 s,100 d,102 f,103 g,104 h,106 j,107 k,108 l,59 ;,39 ',122 z,120 x,99 c,118 v,98 b,110 n,109 m,44 ,,46 .,47 /,32 Space,9 Tab,27 Esc,13 Enter,42 *,43 +" ' Last 2 are for numlock.
CtrlKeys$ = ",94 F1,95 F2,96 F3,97 F4,98 F5,99 F6,100 F7,101 F8,102 F9,103 F10,137 F11,138 F12,146 Insert,147 Delete,132 PgDp,118 PgDn,119 Home,117 End,115 Arrow Lt,141 Arrow Up,145 Arrow Dn,116 Arrow Rt,147 Backspace,17 q,23 w,5 e,18 r,20 t,25 y,21 u,9 i,15 o,16 p,1 a,19 s,4 d,6 f,7 g,8 h,10 j,11 k,12 l,26 z,24 x,3 c,22 v,2 b,14 n,13 m,32 Space,0 2,30 6,31 -"
AltKeys$ = ",104 F1,105 F2,106 F3,108 F5,109 F6,110 F7,111 F8,112 F9,113 F10,139 F11,140 F12,162 Insert,163 Delete,153 PgDp,161 PgDn,151 Home,159 End,155 Arrow Lt,152 Arrow Up,160 Arrow Dn,157 Arrow Rt,14 Backspace,41 `,120 1,121 2,122 3,123 4,124 5,125 6,126 7,127 8,128 9,129 0,130 -,131 =,16 q,17 w,18 e,19 r,20 t,21 y,22 u,23 i,24 o,25 p,26 [,27 ],43 \,30 a,31 s,32 d,33 f,34 g,35 h,36 j,37 k,38 l,39 ;,40 ',44 z,45 x,46 c,47 v,48 b,49 n,50 m,51 , 52,. 53,/"
Do
    _Limit 30
    b$ = InKey$
    If _KeyDown(100303) Or _KeyDown(100304) Then shift = -1 Else If shift Then shift = 0
    If _KeyDown(100305) Or _KeyDown(100306) Then ctrl = -1 Else If ctrl Then ctrl = 0
    If _KeyDown(100307) Or _KeyDown(100308) Then alt = -1 Else If alt Then alt = 0
    If Len(b$) Then
        Sound 1000, .2
        If alt Then
            x$ = AltKeys$
        ElseIf ctrl Then x$ = CtrlKeys$
        ElseIf shift Then x$ = UcaseKeys$ Else x$ = LcaseKeys$
        End If
        If Len(b$) = 1 Then e$ = LTrim$(Str$(Asc(b$))): seed = InStr(x$, "Arrow Rt") + 8 Else e$ = LTrim$(Str$(Asc(Mid$(b$, 2, 1)))): seed = 0
        Do
            j = InStr(seed, x$, "," + e$ + " ")
            If j Then
                key$ = Mid$(x$, j + Len(e$) + 2)
                key$ = Mid$(key$, 1, InStr(key$ + ",", ",") - 1)
                If shift Then
                    j = InStr("`1234567890-=[]\;',./", key$)
                    If j Then key$ = Mid$("~!@#$%^&*()_+{}|:'<>?", j, 1): If key$ = "'" Then key$ = Chr$(34)
                End If
                If key$ = "-Q" Then key$ = Chr$(34) ' Compensate for inability to store a quote mark in a data statement.
                If shift + ctrl + alt Then If Len(key$) = 1 Then key$ = UCase$(key$)
                If shift Then Print "Shift ";
                If ctrl Then Print "Ctrl "; Rem If key$ = "J" Then key$ = "Enter" GLUT error. BTW _Keyhit would return 13 for Ctrl + Enter or Ctrl + J.
                If alt Then Print "Alt ";
                Print key$: Exit Do
            Else
                Print e$, b$: Sound 100, 1: Exit Do ' Something got missed!
            End If
        Loop
    End If
Loop

I included the numlock keypad in this one. As far as AltGr, I've only had one setup with that on my keyboard. I'd have to either do a lookup, or see if virtual keyboard could be used to map those.

Pete
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Wink display unicode text(by windows api) qbfans 10 903 12-21-2025, 12:17 AM
Last Post: TDarcos
  Vacuum Flourescent Display Clock With Alarm SierraKen 5 1,176 06-07-2025, 11:02 PM
Last Post: SierraKen
  Volume display utility eoredson 0 490 09-30-2023, 01:06 AM
Last Post: eoredson

Forum Jump:


Users browsing this thread: 1 Guest(s)