Skip to content

Instantly share code, notes, and snippets.

@hcyang1012
Created January 14, 2018 13:05
Show Gist options
  • Save hcyang1012/8240b431737654d992dc82774b0c57f0 to your computer and use it in GitHub Desktop.
Save hcyang1012/8240b431737654d992dc82774b0c57f0 to your computer and use it in GitHub Desktop.
Write System Call for virtual keyboard
static ssize_t virtKeyboard_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos){
u32 keycode = 0u;
u8 *kernel_buf = (u8*)kzalloc(len,GFP_KERNEL);
int ret = 0;
pr_info(LOG("Length : %d"),len);
if(kernel_buf == NULL){
pr_err(LOG("Not enough memory"));
return -ENOMEM;
}
ret = copy_from_user(kernel_buf,buf,len);
if (ret == 0u){
ret = sscanf(kernel_buf,"%x",&keycode);
if(ret != 1u){
pr_err(LOG("Failed to read keycode"));
kfree(kernel_buf);
return -ENOMEM;
}
pr_info(LOG("Keycode input : %x"),keycode);
kfree(kernel_buf);
keyPressed = (~keyPressed);
input_report_key(virtKeyabord_dev, KEY_A,keyPressed);
input_sync(virtKeyabord_dev);
return len;
}else{
pr_err(LOG("copy_from_user error : %d"),ret);
kfree(kernel_buf);
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment