Author Topic: Is there a reason i cant record ctrl+j?  (Read 4687 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Is there a reason i cant record ctrl+j?
« on: December 22, 2020, 08:13:05 am »
So this is something weird - I don't know if its my keyboard, or my system, or how im writing this code.... but for whatever reason, pressing Ctrl+J doesnt pick up, but Ctrl+L does.

I just need another set of eyes to look at it. This is simple to someone.

Code: QB64: [Select]
  1.     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN ' Both control keys
  2.         ctrl = 1
  3.     ELSE
  4.         ctrl = 0
  5.     END IF
  6.  
  7.     kh = _KEYHIT
  8.  
  9.     IF kh = ASC("L") OR kh = ASC("l") THEN
  10.         IF ctrl = 1 THEN PRINT "ctrl-";
  11.         PRINT CHR$(kh)
  12.     END IF
  13.  
  14.     IF kh = ASC("J") OR kh = ASC("j") THEN
  15.         IF ctrl = 1 THEN PRINT "ctrl-";
  16.         PRINT CHR$(kh)
  17.     END IF
  18.  
You're not done when it works, you're done when it's right.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Is there a reason i cant record ctrl+j?
« Reply #1 on: December 22, 2020, 08:22:25 am »
That is strange.
Shuwatch!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #2 on: December 22, 2020, 08:31:17 am »
okay, so somehow code 13 has something to do with this?...

Code: QB64: [Select]
  1.     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN ' Both control keys
  2.         ctrl = 1
  3.     ELSE
  4.         ctrl = 0
  5.     END IF
  6.  
  7.     kh = _KEYHIT
  8.  
  9.     IF kh = ASC("L") OR kh = ASC("l") THEN
  10.         IF ctrl = 1 THEN PRINT "ctrl-";
  11.         PRINT CHR$(kh)
  12.     END IF
  13.  
  14.     IF kh = 13 THEN
  15.         IF ctrl = 1 THEN PRINT "ctrl-";
  16.         PRINT "j"
  17.     END IF
  18.  
  19.     IF kh = ASC("J") OR kh = ASC("j") THEN
  20.         IF ctrl = 1 THEN PRINT "ctrl-";
  21.         PRINT CHR$(kh)
  22.     END IF
  23.  
  24.  
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #3 on: December 22, 2020, 08:38:15 am »
This captures it in smaller code:

Code: QB64: [Select]
  1.     PRINT "Press ENTER or Ctrl+J"
  2.     DO
  3.         IF _KEYHIT = 13 THEN EXIT DO
  4.     LOOP
  5.     PRINT "Good work.": PRINT
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #4 on: December 22, 2020, 08:43:43 am »
Alright this was solved. It happens for a reason of some kind. Work-around shall be inkey$ to catch the J.
You're not done when it works, you're done when it's right.

FellippeHeitor

  • Guest
Re: Is there a reason i cant record ctrl+j?
« Reply #5 on: December 22, 2020, 08:46:34 am »
CTRL+J translates into CHR$(10) for MS-DOS reasons. Read INKEY$ instead and look for CHR$(10) and you're golden.

Code: QB64: [Select]
  1. PRINT "hit Ctrl+J:"
  2.     k$ = INKEY$
  3.     IF k$ = CHR$(10) THEN PRINT " You did it."
  4.     _LIMIT 30

For reference (http://www.physics.udel.edu/~watson/scen103/ascii.html):
 
Captura de Tela 2020-12-22 às 10.48.02.png
« Last Edit: December 22, 2020, 08:52:17 am by FellippeHeitor »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a reason i cant record ctrl+j?
« Reply #6 on: December 22, 2020, 10:24:52 am »
Just another example of _KEYHIT and _KEYDOWN being broken.  If you're coding for Windows, use my custom keyboard library instead.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #7 on: December 22, 2020, 06:43:36 pm »
That's why I call it _HITKEY. BASICally, INKEY$ rules!!!!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a reason i cant record ctrl+j?
« Reply #8 on: December 22, 2020, 07:29:12 pm »
That's why I call it _HITKEY. BASICally, INKEY$ rules!!!!

Pete

INKEY$ is just as bad.  Try the following, for example:

Code: QB64: [Select]
  1.     i$ = INKEY$
  2.     IF i$ <> "" THEN PRINT ASC(i$, 1)
  3.     _LIMIT 30

Now hit I, CTRL-I, TAB, and CTRL-TAB.  What's the output that you're seeing?

73 (or 105, depending on caps lock or shift state)
9
9
(nothing)

Ctrl-I is the exact same as TAB -- regardless of capslock, or shift-status, and CTRL-TAB doesn't even exist at all.  It's absolutely impossible to generate a ctrl-tab keypress, or to designate the difference between SHFT-CTRL-I, CTRL-I, and TAB.

INKEY$ and _KEYHIT both fail to read multiple keypresses and combinations.  Fellippe's solution is only viable in this one singular instance.  Try to do the same with CTRL-M with INKEY$....  (Hint:  It's the 13th letter of the alphabet, so much like J is 10, M is going to be....  ???)   (Hint 2:  What's the value of the ENTER key?)

When you start looking at extended key presses, or reading all the various key combinations you can make with your keyboard, you're going to have to make your own input handler.  QB64's built in commands aren't up to the task.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #9 on: December 22, 2020, 09:06:48 pm »
QB has always had these "Mickey Mouse" challenges. Ctrl + Tab is certainly one of them, as INKEY$ On KEY, etc. are blocked from detecting this combination. INP(&h60) is the Mickey Mouse workaround, but it isn't perfect, as the status doesn't change until either both keys are released, or ctrl is held while a different key is pressed, before tab is pressed again. Also, you have to press ctrl first or write a more elaborate key handling routine....

Code: QB64: [Select]
  1.     _LIMIT 30
  2.     DEF SEG = 0
  3.     IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN shift% = -1 ELSE shift% = 0
  4.     IF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN ctrl% = -1 ELSE ctrl% = 0
  5.     IF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN ctrlshift% = -1 ELSE ctrlshift% = 0
  6.     DEF SEG
  7.     b$ = INKEY$
  8.     IF ctrl% THEN
  9.         IF INP(96) = 151 THEN
  10.             PRINT "Ctrl + TAB"
  11.             WHILE INP(96) = 151: _LIMIT 30: b$ = INKEY$: WEND
  12.         END IF
  13.     END IF
  14. LOOP UNTIL b$ = CHR$(27)


Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #10 on: December 22, 2020, 09:10:44 pm »

If you're coding for Windows, use my custom keyboard library instead.

...

Fellippe's solution is only viable in this one singular instance.


Same same.

Until there is a single, universal solution to this, I see nobody having the cake and eating it too.

(i think qb64 programs should target every platform supported by the compiler. i can't really invest in windows-only anything.)
You're not done when it works, you're done when it's right.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a reason i cant record ctrl+j?
« Reply #11 on: December 24, 2020, 03:06:29 pm »
QB has always had these "Mickey Mouse" challenges. Ctrl + Tab is certainly one of them, as INKEY$ On KEY, etc. are blocked from detecting this combination. INP(&h60) is the Mickey Mouse workaround, but it isn't perfect, as the status doesn't change until either both keys are released, or ctrl is held while a different key is pressed, before tab is pressed again. Also, you have to press ctrl first or write a more elaborate key handling routine....

Code: QB64: [Select]
  1.     _LIMIT 30
  2.     DEF SEG = 0
  3.     IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN shift% = -1 ELSE shift% = 0
  4.     IF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN ctrl% = -1 ELSE ctrl% = 0
  5.     IF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN ctrlshift% = -1 ELSE ctrlshift% = 0
  6.     DEF SEG
  7.     b$ = INKEY$
  8.     IF ctrl% THEN
  9.         IF INP(96) = 151 THEN
  10.             PRINT "Ctrl + TAB"
  11.             WHILE INP(96) = 151: _LIMIT 30: b$ = INKEY$: WEND
  12.         END IF
  13.     END IF
  14. LOOP UNTIL b$ = CHR$(27)


Pete

@Pete -- Doesn't work.  Run it and hit CTRL-TAB, and then hit CTRL-I.   You have the exact same issue here that INKEY$ has.  You can't tell the difference in those two keypresses at all.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Is there a reason i cant record ctrl+j?
« Reply #12 on: December 28, 2020, 04:22:23 pm »
I was wondering, Is there a way to tap into glut's keyboard function to get keypresses?  Would there be any difference in doing that?   I was looking at the glut functions and can get glutGet and glutDeviceGet to work, but that's all I have experience with so far.  How much of glut functions can we access from QB64 code? (Im a newbie in that stuff...)

- Dav
« Last Edit: December 28, 2020, 04:31:56 pm by Dav »