VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I'm trying to get my PS/2 keyboard emulation correct. I already have basic handlers that convert from the platform (PSP(w/ OSK when used), Windows or Linux) to an universal format used by the keyboard (104 keys as numbers).

So far I've implemented:
- When a key is pressed, it's press count (0-103) is registered and the key is marked as pressed.
- When a key is released, it's marked as released on top of it's pressed status (so both pressed and released when pressed, else nothing happens).

In the timer (ran at a high speed):
- When a key is marked as pressed and released, it immediately sends it's release code to the PS/2 keyboard buffer and marked as unpressed (reset to it's default state).

Then within the same timer, after processing the above information (key releases), it starts checking for input speed and new key presses:
- When no keys are pressed anymore, the step (the delay in 1ms periods between checking for input and processing it) and key_pressed_counter(increasing number, containing 1 more than the last key number pressed. This goes from 0-last key pressed, which is an incrementing number containing the order of key presses (including releases which were pressed)) are cleared.
- Finally, the input is handled:
-- When the current 1ms count (incremented by 1 each interval) exceeds the step (The amount of ms between checking and processing input)), (new) input is handled:
-- The current 1ms count is reset to zero.
-- When keys are pressed:
--- keypresses are handled.
--- The next step is calculated (depending on if there are active keys and step. If step is set, it's set to the repeat rate, else repeat delay)).

The handling of a key press checks the step variable. If it's set it's assumed the key is typematic, else non-typematic.
- Typematic key(s) are handled only the last key pressed (the earlier ones not being resent). When a key is released, the last pressed key becomes the active key (so if you press A,D,S,F, release F then S becomes the active key(the last in the line of active keys order still pressed)).
- Non-typematic key(s) are always pressed (more at one pressed key gets triggered in one loop before returning to the caller).

Is this correct? Or have I made a mistake in my keyboard emulation (PS/2 keyboard)?

https://bitbucket.org/superfury/x86emu/src/2d … ard.c?at=master

Edit: Fixed it according to the official documentation, stopping input when any key is released (including rapid input).

https://bitbucket.org/superfury/x86emu/src/8a … ard.c?at=master

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 4, by Azarien

User metadata
Rank Oldbie
Rank
Oldbie

Edit: Fixed it according to the official documentation, stopping input when any key is released (including rapid input).

My keyboard stops repeating only when the repeating key is released.

Reply 2 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

Exactly what key is that? The first key pressed or the last key pressed? My emulation currently uses the last key(which repeats while it's pressed and not released). Releasing any key releases all keys but Ctrl, Alt and Shift(both left and right). This makes the input the same as my keyboard(Logitech) within Windows 10's notepad.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 3 of 4, by Azarien

User metadata
Rank Oldbie
Rank
Oldbie

The last key is being repeated, and releasing any other key does not stop it.
Releasing Shift does not stop repetition, but changes the case of repeated character.
Pressing Shift stops repetition.

Reply 4 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

So the repitition stops when ctrl/alt/shift is pressed again after repitition. Is this true? Also, does the currently pressed key change to shift repeating, or stop completely? (Although you'll need some kind of input sniffer letting you see the press and release data to do that)?

Also, would any keyboard sniffer be viewed as a Trojan in any antivirus software? Is there any safe one to look at my keyboard packets?

Edit: I've solved this problem by simply logging within my emulator itself (in the onKeyPress and onKeyRelease functions, which get input translated from SDL, which has repeat enabled using it's default settings).

0:00:17:93.7.0597: Keypress:esc

0:00:18:02.1.0293: Keyrelease:esc

0:00:19:72.0.0794: Keypress:esc

0:00:19:78.8.0004: Keyrelease:esc

0:00:28:06.8.0477: Keypress:lshift

0:00:29:26.8.0053: Keypress:a

0:00:29:36.7.0910: Keyrelease:a

0:00:29:70.9.0754: Keypress:a

0:00:29:78.9.0059: Keyrelease:a

0:00:30:15.4.0652: Keypress:a

0:00:30:23.0.0358: Keyrelease:a

0:00:32:44.0.0269: Keypress:a

0:00:32:97.2.0178: Keypress:a

0:00:33:00.3.0822: Keypress:a

0:00:33:03.4.0915: Keypress:a

0:00:33:06.5.0623: Keypress:a

0:00:33:09.6.0328: Keypress:a

0:00:33:12.7.0999: Keypress:a

0:00:33:15.8.0223: Keypress:a

0:00:33:18.9.0926: Keypress:a

0:00:33:22.0.0558: Keypress:a

0:00:33:22.4.0630: Keypress:j

0:00:33:75.8.0474: Keypress:j

0:00:33:79.0.0116: Keypress:j

0:00:33:82.0.0766: Keypress:j

0:00:33:85.1.0363: Keypress:j

0:00:33:88.2.0001: Keypress:j

0:00:33:91.3.0655: Keypress:j

0:00:33:94.4.0293: Keypress:j

0:00:33:97.4.0940: Keypress:j

Show last 25 lines
0:00:34:00.6.0538: Keypress:j

0:00:34:03.7.0168: Keypress:j

0:00:34:06.8.0808: Keypress:j

0:00:34:09.9.0440: Keypress:j

0:00:34:11.0.0546: Keyrelease:j

0:00:38:47.7.0112: Keyrelease:lshift

0:00:39:64.3.0776: Keypress:lshift

0:00:41:96.3.0618: Keyrelease:lshift

0:00:42:63.5.0965: Keypress:lshift

0:00:43:35.2.0335: Keyrelease:lshift

0:00:43:95.1.0679: Keypress:lshift

0:00:45:44.2.0526: Keyrelease:lshift

0:00:45:58.2.0810: Keyrelease:a

So this means that releasing non-Ctrl/Alt/Shift stops input, but Ctrl,Alt and Shift aren't repeating? Also, release codes aren't sent until they're actually released on the keyboard (it just stops sending keypress codes(surpresses them) for those keys).

Edit: I've worked a bit on it. It seems to run reasonably well, but with a little strange stuff at the end:
Input data from SDL:

0:00:18:06.1.0679: Keypress:esc

0:00:18:13.7.0754: Keyrelease:esc

0:00:19:79.7.0212: Keypress:esc

0:00:19:83.2.0622: Keyrelease:esc

0:00:24:04.0.0475: Keypress:lshift

0:00:25:83.7.0382: Keypress:a

0:00:26:36.9.0475: Keypress:a

0:00:26:39.9.0929: Keypress:a

0:00:26:43.1.0264: Keypress:a

0:00:26:43.6.0623: Keypress:s

0:00:26:96.8.0770: Keypress:s

0:00:26:99.9.0330: Keypress:s

0:00:27:03.0.0712: Keypress:s

0:00:27:06.1.0122: Keypress:s

0:00:27:09.2.0412: Keypress:s

0:00:27:12.3.0335: Keypress:s

0:00:27:15.4.0358: Keypress:s

0:00:27:18.4.0680: Keypress:s

0:00:27:20.7.0507: Keyrelease:s

0:00:27:95.4.0545: Keyrelease:a

0:00:29:09.7.0084: Keypress:a

0:00:29:62.9.0440: Keypress:a

0:00:29:66.0.0518: Keypress:a

0:00:29:69.1.0713: Keypress:a

0:00:29:72.3.0042: Keypress:a

0:00:29:75.3.0360: Keypress:a

0:00:29:75.8.0792: Keypress:s

0:00:30:29.0.0944: Keypress:s

0:00:30:32.2.0041: Keypress:s

0:00:30:35.3.0048: Keypress:s

Show last 286 lines
0:00:30:38.4.0411: Keypress:s

0:00:30:41.5.0750: Keypress:s

0:00:30:44.8.0092: Keypress:s

0:00:30:47.9.0037: Keypress:s

0:00:30:51.0.0343: Keypress:s

0:00:30:52.1.0152: Keyrelease:s

0:00:32:67.5.0374: Keypress:s

0:00:33:20.7.0133: Keypress:s

0:00:33:23.1.0171: Keyrelease:s

0:00:33:61.3.0760: Keypress:s

0:00:33:96.7.0800: Keyrelease:s

0:00:34:26.9.0111: Keypress:s

0:00:34:70.4.0536: Keyrelease:s

0:00:34:98.1.0029: Keypress:s

0:00:35:49.5.0061: Keyrelease:s

0:00:37:88.5.0165: Keyrelease:lshift

0:00:39:16.1.0984: Keyrelease:a

0:00:45:15.0.0092: Keypress:lshift

0:00:45:71.1.0208: Keypress:a

0:00:46:24.3.0991: Keypress:a

0:00:46:27.4.0982: Keypress:a

0:00:46:30.6.0308: Keypress:a

0:00:46:33.7.0679: Keypress:a

0:00:46:36.8.0022: Keypress:a

0:00:46:39.9.0222: Keypress:a

0:00:46:43.0.0495: Keypress:a

0:00:46:46.0.0993: Keypress:a

0:00:46:49.2.0352: Keypress:a

0:00:46:52.3.0748: Keypress:a

0:00:46:55.4.0128: Keypress:a

0:00:46:58.5.0508: Keypress:a

0:00:46:61.6.0474: Keypress:a

0:00:46:64.7.0575: Keypress:a

0:00:46:67.7.0938: Keypress:a

0:00:46:68.1.0379: Keyrelease:lshift

0:00:46:70.8.0925: Keypress:a

0:00:46:74.0.0206: Keypress:a

0:00:46:77.0.0889: Keypress:a

0:00:46:80.2.0572: Keypress:a

0:00:46:83.3.0316: Keypress:a

0:00:46:86.3.0979: Keypress:a

0:00:46:89.5.0715: Keypress:a

0:00:46:92.6.0431: Keypress:a

0:00:46:95.7.0134: Keypress:a

0:00:46:98.8.0821: Keypress:a

0:00:47:01.9.0512: Keypress:a

0:00:47:05.0.0159: Keypress:a

0:00:47:08.1.0845: Keypress:a

0:00:47:11.2.0520: Keypress:a

0:00:47:14.4.0207: Keypress:a

0:00:47:17.5.0488: Keypress:a

0:00:47:20.6.0179: Keypress:a

0:00:47:23.6.0834: Keypress:a

0:00:47:26.8.0562: Keypress:a

0:00:47:29.9.0273: Keypress:a

0:00:47:33.0.0034: Keypress:a

0:00:47:36.1.0750: Keypress:a

0:00:47:39.2.0412: Keypress:a

0:00:47:42.3.0112: Keypress:a

0:00:47:45.4.0811: Keypress:a

0:00:47:48.5.0498: Keypress:a

0:00:47:51.6.0177: Keypress:a

0:00:47:54.7.0938: Keypress:a

0:00:47:57.8.0674: Keypress:a

0:00:47:61.0.0390: Keypress:a

0:00:47:64.0.0655: Keypress:a

0:00:47:67.2.0342: Keypress:a

0:00:47:70.3.0017: Keypress:a

0:00:47:73.4.0699: Keypress:a

0:00:47:76.5.0366: Keypress:a

0:00:47:79.6.0012: Keypress:a

0:00:47:82.7.0252: Keypress:a

0:00:47:85.7.0956: Keypress:a

0:00:47:88.9.0647: Keypress:a

0:00:47:92.0.0322: Keypress:a

0:00:47:95.1.0009: Keypress:a

0:00:47:98.2.0712: Keypress:a

0:00:48:01.3.0391: Keypress:a

0:00:48:04.4.0083: Keypress:a

0:00:48:07.6.0781: Keypress:a

0:00:48:10.8.0058: Keypress:a

0:00:48:13.8.0737: Keypress:a

0:00:48:16.9.0379: Keypress:a

0:00:48:20.0.0050: Keypress:a

0:00:48:23.0.0746: Keypress:a

0:00:48:26.2.0445: Keypress:a

0:00:48:26.9.0539: Keypress:lshift

0:00:48:29.3.0144: Keypress:a

0:00:48:32.3.0803: Keypress:a

0:00:48:35.5.0559: Keypress:a

0:00:48:38.6.0341: Keypress:a

0:00:48:41.7.0073: Keypress:a

0:00:48:44.8.0751: Keypress:a

0:00:48:47.8.0447: Keyrelease:lshift

0:00:48:47.9.0463: Keypress:a

0:00:48:51.0.0114: Keypress:a

0:00:48:54.1.0358: Keypress:a

0:00:48:57.3.0008: Keypress:a

0:00:48:60.3.0654: Keypress:a

0:00:48:63.4.0288: Keypress:a

0:00:48:66.5.0946: Keypress:a

0:00:48:69.0.0584: Keypress:lshift

0:00:48:69.6.0638: Keypress:a

0:00:48:72.8.0369: Keypress:a

0:00:48:75.9.0024: Keypress:a

0:00:48:79.0.0727: Keypress:a

0:00:48:82.2.0401: Keypress:a

0:00:48:85.3.0056: Keypress:a

0:00:48:87.1.0242: Keyrelease:lshift

0:00:48:88.4.0779: Keypress:a

0:00:48:91.5.0421: Keypress:a

0:00:48:94.6.0055: Keypress:a

0:00:48:97.7.0763: Keypress:a

0:00:49:00.7.0999: Keypress:a

0:00:49:03.9.0678: Keypress:a

0:00:49:06.7.0367: Keypress:lshift

0:00:49:07.0.0394: Keypress:a

0:00:49:10.1.0048: Keypress:a

0:00:49:13.2.0686: Keypress:a

0:00:49:16.3.0332: Keypress:a

0:00:49:19.4.0974: Keypress:a

0:00:49:22.6.0624: Keypress:a

0:00:49:25.5.0291: Keyrelease:lshift

0:00:49:25.7.0311: Keypress:a

0:00:49:28.7.0974: Keypress:a

0:00:49:31.9.0640: Keypress:a

0:00:49:35.0.0302: Keypress:a

0:00:49:38.0.0953: Keypress:a

0:00:49:41.2.0611: Keypress:a

0:00:49:44.3.0323: Keypress:a

0:00:49:47.4.0575: Keypress:a

0:00:49:50.5.0258: Keypress:a

0:00:49:53.6.0929: Keypress:a

0:00:49:56.7.0583: Keypress:a

0:00:49:59.8.0225: Keypress:a

0:00:49:62.9.0875: Keypress:a

0:00:49:66.0.0509: Keypress:a

0:00:49:69.1.0155: Keypress:a

0:00:49:72.1.0794: Keypress:a

0:00:49:75.3.0439: Keypress:a

0:00:49:78.4.0069: Keypress:a

0:00:49:81.4.0716: Keypress:a

0:00:49:83.6.0932: Keyrelease:a

Emulated input:

0:00:18:06.3.0099: Key press: esc

0:00:18:13.9.0186: Key release: esc

0:00:19:79.8.0657: Key press: esc

0:00:19:83.4.0022: Key release: esc

0:00:24:04.1.0933: Key press: lshift

0:00:25:84.1.0830: Key press: a

0:00:26:10.5.0697: Key press: a

0:00:26:14.1.0291: Key press: a

0:00:26:17.6.0885: Key press: a

0:00:26:21.2.0471: Key press: a

0:00:26:24.9.0471: Key press: a

0:00:26:28.5.0048: Key press: a

0:00:26:32.0.0698: Key press: a

0:00:26:35.6.0368: Key press: a

0:00:26:39.2.0450: Key press: a

0:00:26:42.8.0869: Key press: a

0:00:26:46.5.0199: Key press: s

0:00:26:72.9.0266: Key press: s

0:00:26:76.4.0861: Key press: s

0:00:26:80.0.0479: Key press: s

0:00:26:83.6.0094: Key press: s

0:00:26:87.1.0838: Key press: s

0:00:26:90.7.0485: Key press: s

0:00:26:94.3.0164: Key press: s

0:00:26:97.9.0428: Key press: s

0:00:27:01.7.0236: Key press: s

0:00:27:05.3.0614: Key press: s

0:00:27:09.0.0016: Key press: s

0:00:27:12.6.0355: Key press: s

0:00:27:16.2.0785: Key press: s

Show last 176 lines
0:00:27:19.9.0129: Key press: s

0:00:27:20.8.0804: Key release: s

0:00:27:95.5.0989: Key release: a

0:00:29:11.1.0594: Key press: a

0:00:29:37.5.0604: Key press: a

0:00:29:41.1.0203: Key press: a

0:00:29:44.8.0222: Key press: a

0:00:29:48.3.0843: Key press: a

0:00:29:51.9.0450: Key press: a

0:00:29:55.5.0073: Key press: a

0:00:29:59.0.0747: Key press: a

0:00:29:62.6.0411: Key press: a

0:00:29:66.2.0533: Key press: a

0:00:29:69.9.0178: Key press: a

0:00:29:73.5.0510: Key press: a

0:00:29:77.1.0864: Key press: s

0:00:30:03.6.0069: Key press: s

0:00:30:07.1.0728: Key press: s

0:00:30:10.7.0343: Key press: s

0:00:30:14.2.0980: Key press: s

0:00:30:17.8.0599: Key press: s

0:00:30:21.5.0617: Key press: s

0:00:30:25.1.0264: Key press: s

0:00:30:28.6.0912: Key press: s

0:00:30:32.3.0051: Key press: s

0:00:30:35.9.0518: Key press: s

0:00:30:39.5.0884: Key press: s

0:00:30:43.2.0257: Key press: s

0:00:30:46.8.0619: Key press: s

0:00:30:50.4.0914: Key press: s

0:00:30:52.2.0160: Key release: s

0:00:32:67.8.0835: Key press: s

0:00:32:94.2.0992: Key press: s

0:00:32:97.8.0615: Key press: s

0:00:33:01.5.0651: Key press: s

0:00:33:05.1.0297: Key press: s

0:00:33:08.6.0971: Key press: s

0:00:33:12.2.0619: Key press: s

0:00:33:15.8.0297: Key press: s

0:00:33:19.3.0979: Key press: s

0:00:33:23.0.0776: Key press: s

0:00:33:23.2.0453: Key release: s

0:00:33:63.9.0336: Key press: s

0:00:33:90.3.0565: Key press: s

0:00:33:93.9.0182: Key press: s

0:00:33:96.9.0240: Key release: s

0:00:34:30.5.0178: Key press: s

0:00:34:56.9.0655: Key press: s

0:00:34:60.5.0331: Key press: s

0:00:34:64.1.0020: Key press: s

0:00:34:67.6.0778: Key press: s

0:00:34:70.5.0982: Key release: s

0:00:35:00.6.0649: Key press: s

0:00:35:27.1.0399: Key press: s

0:00:35:30.7.0095: Key press: s

0:00:35:34.2.0788: Key press: s

0:00:35:37.9.0873: Key press: s

0:00:35:41.5.0562: Key press: s

0:00:35:45.1.0230: Key press: s

0:00:35:48.6.0955: Key press: s

0:00:35:49.6.0499: Key release: s

0:00:37:88.6.0603: Key release: lshift

0:00:39:16.3.0368: Key release: a

0:00:45:15.1.0575: Key press: lshift

0:00:45:73.7.0963: Key press: a

0:00:46:00.2.0733: Key press: a

0:00:46:03.8.0417: Key press: a

0:00:46:07.4.0101: Key press: a

0:00:46:11.1.0203: Key press: a

0:00:46:14.6.0908: Key press: a

0:00:46:18.2.0588: Key press: a

0:00:46:21.8.0297: Key press: a

0:00:46:25.4.0485: Key press: a

0:00:46:29.0.0862: Key press: a

0:00:46:32.7.0243: Key press: a

0:00:46:36.3.0640: Key press: a

0:00:46:40.0.0233: Key press: a

0:00:46:43.6.0938: Key press: a

0:00:46:47.3.0466: Key press: a

0:00:46:51.1.0280: Key press: a

0:00:46:54.7.0698: Key press: a

0:00:46:58.4.0115: Key press: a

0:00:46:62.0.0512: Key press: a

0:00:46:65.7.0020: Key press: a

0:00:46:68.2.0391: Key release: lshift

0:00:49:83.7.0940: Key release: a

0:00:49:83.8.0431: Key press: lshift

0:00:49:83.9.0447: Key release: lshift

Source code of the keyboard emulation: https://bitbucket.org/superfury/x86emu/src/a6 … ard.c?at=master

Anyone can see what's going wrong here? Or is this simply because SDL uses the default rate(for delay and repeat), while my application use what is set by the BIOS+MS-DOS 5.0?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io