2014-08-28 10 views

回答

2

在這裏被用於與夫特使用的功能,寫在夫特:

func GetKeyPress() -> Int 
{ 
    var key: Int = 0 
    var c: cc_t = 0 
    var cct = (c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c) // Set of 20 Special Characters 
    var oldt: termios = termios(c_iflag: 0, c_oflag: 0, c_cflag: 0, c_lflag: 0, c_cc: cct, c_ispeed: 0, c_ospeed: 0) 

    tcgetattr(STDIN_FILENO, &oldt) // 1473 
    var newt = oldt 
    newt.c_lflag = 1217 // Reset ICANON and Echo off 
    tcsetattr(STDIN_FILENO, TCSANOW, &newt) 
    key = Int(getchar()) // works like "getch()" 
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt) 
    return key 
} 
1

下面是用於與Objective-C和夫特使用的功能,寫入C:

#include <stdio.h> 
#include <unistd.h> 
#include <termios.h> 
#include <string.h> 

int Get_Key (void) { 
    int key; 
    struct termios oldt, newt; 
    tcgetattr(STDIN_FILENO, &oldt); // 1473 
    memcpy((void *)&newt, (void *)&oldt, sizeof(struct termios)); 
    newt.c_lflag &= ~(ICANON); // Reset ICANON 
    newt.c_lflag &= ~(ECHO); // Echo off, after these two .c_lflag = 1217 
    tcsetattr(STDIN_FILENO, TCSANOW, &newt); // 1217 
    key=getchar(); // works like "getch()" 
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt); 
    return key; 
} 
相關問題