Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
dheygere committed Apr 22, 2023
1 parent f8cfb68 commit 30cca53
Show file tree
Hide file tree
Showing 12 changed files with 754 additions and 0 deletions.
Binary file added dist/hidapi.dll
Binary file not shown.
Binary file added dist/setFnKeys.exe
Binary file not shown.
Binary file added dist/setMediaKeys.exe
Binary file not shown.
603 changes: 603 additions & 0 deletions hidapi/include/hidapi.h

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions hidapi/include/hidapi_winapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
libusb/hidapi Team
Copyright 2022, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
https://github.com/libusb/hidapi .
********************************************************/

/** @file
* @defgroup API hidapi API
*
* Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
*/

#ifndef HIDAPI_WINAPI_H__
#define HIDAPI_WINAPI_H__

#include <guiddef.h>

#include "hidapi.h"

#ifdef __cplusplus
extern "C" {
#endif

/** @brief Get the container ID for a HID device.
Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
This function returns the `DEVPKEY_Device_ContainerId` property of
the given device. This can be used to correlate different
interfaces/ports on the same hardware device.
@ingroup API
@param dev A device handle returned from hid_open().
@param guid The device's container ID on return.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_winapi_get_container_id(hid_device *dev, GUID *container_id);

#ifdef __cplusplus
}
#endif

#endif
Binary file added hidapi/x64/hidapi.dll
Binary file not shown.
Binary file added hidapi/x64/hidapi.lib
Binary file not shown.
Binary file added hidapi/x64/hidapi.pdb
Binary file not shown.
Binary file added hidapi/x86/hidapi.dll
Binary file not shown.
Binary file added hidapi/x86/hidapi.lib
Binary file not shown.
Binary file added hidapi/x86/hidapi.pdb
Binary file not shown.
93 changes: 93 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Goal
This program sets the function keys for the Logitech K380 bluetooth keyboard on Windows.
Having the F1-F12 without pressing the Fn key is nice for developers.
I wanted a simple way to do the same as the Options/Options+ software WITHOUT their
continuously running processes.
* How to build
- prerequisite : install mingw
- build setFnKeys.exe with :
gcc main.c -o dist/setFnKeys.exe -I hidapi/include -L hidapi/x86 -lhidapi
- build setMediaKeys.exe with :
gcc main.c -D setMediaKeys -o dist/setMediaKeys.exe -I hidapi/include -L hidapi/x86 -lhidapi
* Inspiration
code from : https://github.com/keighrim/k810fn/blob/master/win/k810fn/k810fnCLI.cpp
values from : https://github.com/jergusg/k380-function-keys-conf/blob/master/k380_conf.c
*/

#include <stdio.h> // printf
#include <wchar.h> // wchar_t

#include <hidapi.h>

#define MAX_STR 255

int main(int argc, char *argv[])
{
int seq_len = 7;
const unsigned char k380_seq_fkeys_on[] = {0x10, 0xff, 0x0b, 0x1e, 0x00, 0x00, 0x00};
const unsigned char k380_seq_fkeys_off[] = {0x10, 0xff, 0x0b, 0x1e, 0x01, 0x00, 0x00};
int k380_vid = 0x46d;
int k380_pid = 0xb342;
static const int TARGET_USAGE = 1;
static const int TARGET_USAGE_PAGE = 65280;

int res;
int result = -1;
unsigned char buf[65];
wchar_t wstr[MAX_STR];
hid_device *handle;
struct hid_device_info *devs, *cur_dev;

// Initialize the hidapi library
res = hid_init();

devs = hid_enumerate(k380_vid, k380_pid);
cur_dev = devs;

while (cur_dev)
{
if (cur_dev->usage == TARGET_USAGE && cur_dev->usage_page == TARGET_USAGE_PAGE)
{
handle = hid_open_path(cur_dev->path);

#ifdef setMediaKeys
printf("Set media keys as default");
res = hid_write(handle, k380_seq_fkeys_off, seq_len);
#else
printf("Set function keys as default");
res = hid_write(handle, k380_seq_fkeys_on, seq_len);
#endif

if (res != seq_len)
{
printf("error: %ls\n", hid_error(handle));
}

hid_close(handle);
if (res < 0)
{
result = -1;
break;
}
else
{
result = 0;
break;
}
}
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);

hid_exit();
return result;
}

0 comments on commit 30cca53

Please sign in to comment.