سلام
توی لینک زیر یه فایلی قرار داره، که این کار رو انجام میده:
CH = GETKEY waits for a single keypress and returns the ASCII code. It accepts all ascii characters, including backspace (8), space (32), enter (13), etc, that can be typed on the keyboard. Non-ascii keys (ctrl, alt, ..) return a NaN. CH is a double.
CH = GETKEY(N) waits for N keypresses and returns their ASCII codes. GETKEY(1) is the same as GETKEY without arguments.
GETKEY('non-ascii') or GETKEY(N,'non-ascii') uses non-documented matlab features to return a string describing the key pressed. In this way keys like ctrl, alt, tab etc. can also distinguished. The return is a string (when N = 1) or a cell array of strings.
[CH,T] = GETKEY(...) also returns the time between the start of the function and each keypress. This is, however, not that accurate.
This function is kind of a workaround for getch in C. It uses a modal, but non-visible window, which does show up in the taskbar.
C-language keywords: KBHIT, KEYPRESS, GETKEY, GETCH